Jump to content
View in the app

A better way to browse. Learn more.

Andhrafriends.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Our forum software has been upgraded to the latest version and we are currently experiencing temporary technical issues. Our server administrator is actively working to resolve them, and the forum should be fully operational within the next few hours. Thank you for your patience and understanding.

Linux/Shell/Bash/sed experts ravali

Featured Replies

need urgent help 

 

I have a file with data like this(50K lines unnay file lo)

cat file

test:testA:testB:testC:testD:testE:testF

test1:test1A:test1B:test1C:testD:test1E:test1F

test2:test2A:test2B:test2C:testD:test2E:test2F

test3:test3A:test3B:test3C:testD:test3E:test3F

test4:test4A:test4B:test4C:testD:test4E:test4F

 

 

My task is to change few lines from this file based on  a match 

 

cat list

test1

test2

 

I want to change testD to testXX only on the lines that matches with list

 

i tried this

 

for i in `cat list`

do

grep $i file | sed -i 's/testD/testXX/g' file

done

 

but it is replacing everyline. My task is to update these only but everyhting else stay as is.

test1:test1A:test1B:test1C:testD:test1E:test1F

test2:test2A:test2B:test2C:testD:test2E:test2F

 

 

HELP please !!!!

 

if i understand this right. you want to replace testD with Testxxx for lines starting with test1 and test2? 

 

you could grep ^ to match only lines with start with test1 an test2 from list file. 

  • Author
10 minutes ago, maverick19 said:

if i understand this right. you want to replace testD with Testxxx for lines starting with test1 and test2? 

 

you could grep ^ to match only lines with start with test1 an test2 from list file. 

How do i use grep ^ bhayya .. I tried this and this is exactly what i want. But this is only printing result. How do i make changes directly in fil

 

for i in `cat list`;  do grep $i file | sed 's/testD/testXX/g' ;  done

test1:test1A:test1B:test1C:testXX:test1E:test1F

test2:test2A:test2B:test2C:testXX:test2E:test2F

 

 

 

Quote

tr '{match}' '{replace}' < input.txt > output.txt


 

  • Author
7 minutes ago, dasari4kntr said:


 

I dont think tr will work in my case. I want to change only the lines that match with the file "list" not every single line

cat list

test1

test2

3 minutes ago, dingdong143 said:

I dont think tr will work in my case. I want to change only the lines that match with the file "list" not every single line

cat list

test1

test2

AWK. ..?

58 minutes ago, dingdong143 said:

need urgent help 

 

I have a file with data like this(50K lines unnay file lo)

cat file

test:testA:testB:testC:testD:testE:testF

test1:test1A:test1B:test1C:testD:test1E:test1F

test2:test2A:test2B:test2C:testD:test2E:test2F

test3:test3A:test3B:test3C:testD:test3E:test3F

test4:test4A:test4B:test4C:testD:test4E:test4F

 

 

My task is to change few lines from this file based on  a match 

 

cat list

test1

test2

 

I want to change testD to testXX only on the lines that matches with list

 

i tried this

 

for i in `cat list`

do

grep $i file | sed -i 's/testD/testXX/g' file

done

 

but it is replacing everyline. My task is to update these only but everyhting else stay as is.

test1:test1A:test1B:test1C:testD:test1E:test1F

test2:test2A:test2B:test2C:testD:test2E:test2F

 

 

HELP please !!!!

 

You dont need to grep for it. Sed has an option to search for matching variables.  try something like this 

for i in `cat list`; do  sed -i.bak '/$i/s/testD/testXX/g' file ; done

Just now, chingchang said:

You dont need to grep for it. Sed has an option to search for matching variables.  try something like this 

for i in `cat list`; do  sed -i.bak '/$i/s/testD/testXX/g' file ; done

 

1 hour ago, dingdong143 said:

need urgent help 

 

I have a file with data like this(50K lines unnay file lo)

cat file

test:testA:testB:testC:testD:testE:testF

test1:test1A:test1B:test1C:testD:test1E:test1F

test2:test2A:test2B:test2C:testD:test2E:test2F

test3:test3A:test3B:test3C:testD:test3E:test3F

test4:test4A:test4B:test4C:testD:test4E:test4F

 

 

My task is to change few lines from this file based on  a match 

 

cat list

test1

test2

 

I want to change testD to testXX only on the lines that matches with list

 

i tried this

 

for i in `cat list`

do

grep $i file | sed -i 's/testD/testXX/g' file

done

 

but it is replacing everyline. My task is to update these only but everyhting else stay as is.

test1:test1A:test1B:test1C:testD:test1E:test1F

test2:test2A:test2B:test2C:testD:test2E:test2F

 

 

HELP please !!!!

 

Actually, use double quotes as it is a variable. Try this 

 

 

for i in `cat list`; do  sed -i.bak "/$i/s/testD/testXX/g" file ; done

4 hours ago, dingdong143 said:

How do i use grep ^ bhayya .. I tried this and this is exactly what i want. But this is only printing result. How do i make changes directly in fil

 

for i in `cat list`;  do grep $i file | sed 's/testD/testXX/g' ;  done

test1:test1A:test1B:test1C:testXX:test1E:test1F

test2:test2A:test2B:test2C:testXX:test2E:test2F

 

 

 

try sed directly on the file. 

 

 

string before /s is used to search the lines with that value and replace testXX with testD in those lines

for i in `cat list`; do 

sed -i.txt '/^$1/s/testXX/testD/' text.txt 

done

 

Create an account or sign in to comment

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.