LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-01-2003, 01:53 PM   #1
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Rep: Reputation: 15
bash scripting - editing files


How would you, for example, replace the number in the Nth column (columns are consecutive characters separated by blank space) of the line that contains "bleh" in the file called FILENAME with 12345?

Thanks.
 
Old 07-01-2003, 02:22 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
How about somehting like:
Code:
#!/bin/bash

for i in `cat file.txt`; do
   if [ `echo "$i" | grep bleh` ]; then
      echo $new
   else
      echo "$i"
   fi
done
I'm not too sure how you would be best to get the $new variable as I'm not sure what your line looks like from your description. You could probably use awk.
 
Old 07-01-2003, 02:27 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Sorry - I should have said to change the file you will need to echo it into the file otherwise it will appear on the screen.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
moving files that have spaces in variables -bash scripting bhar0761 Programming 10 09-22-2005 07:30 AM
BASH Scripting akilles Linux - Newbie 5 11-10-2004 07:26 PM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 04:09 AM
Bash scripting Gunslinger_ROL Programming 5 09-28-2004 11:37 AM
bash scripting - editing files brian0918 Programming 1 06-30-2003 06:16 PM


All times are GMT -5. The time now is 08:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration