LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-30-2003, 06:47 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.

Last edited by brian0918; 06-30-2003 at 06:50 PM.
 
Old 06-30-2003, 07:16 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Code:
#!/bin/sh

FILENAME="$HOME/file.txt"

mv -f ${FILENAME} ${FILENAME}.old
awk '/bleh/{$4=12345 ; print}' ${FILENAME}.old >${FILENAME}
 
  


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 08:30 AM
BASH Scripting akilles Linux - Newbie 5 11-10-2004 08:26 PM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 05:09 AM
Bash scripting Gunslinger_ROL Programming 5 09-28-2004 12:37 PM
bash scripting - editing files brian0918 Linux - Newbie 2 07-01-2003 03:27 PM


All times are GMT -5. The time now is 04:09 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