LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 05-14-2004, 06:42 AM   #1
pantera
Member
 
Registered: May 2004
Posts: 80

Rep: Reputation: 15
editing a file using awk


how to edit a file using awk
i tried cat $fname | sed
is it alright?
 
Old 05-14-2004, 08:40 AM   #2
TheOther1
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Distribution: RHAS 2.1, RHEL3, RHEL4, SLES 8.3, SLES 9, SLES9_64, SuSE 9.3 Pro, Ubuntu, Gentoo
Posts: 335

Rep: Reputation: 32
What are you trying to do? sed and awk are two different programs but work very well together. sed is an inline editor and awk is pattern scanning language. Both have overlapping features.

If you want to replace something in a file, you can:
cat $fname | sed s/old_pattern/new_pattern/ > $new_fname
ie.
cat test.txt | sed s/"Robert Smith"/"Bob Smith"/ > newtest.txt
and that would replace every occurance of Robert Smith with Bob Smith

Note: the search criteria, Robert Smith, is case sensitive.

For more complex things like tables and strict formatting, you might be better off with awk. The Oreilly sed & awk book, Second Edition is a great reference.
 
  


Reply



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
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 11:16 AM
awk: fatal:cannot open file for reading (no such file or Directory) in Linux sangati vishwanath Linux - Software 4 07-06-2005 12:59 AM
awk and change file content Ayman.mashal Programming 4 06-02-2005 06:03 AM
Formating a file with awk tifu Programming 5 03-16-2005 11:35 PM
Getting awk to extract scripts from a file jspaceman Programming 5 11-24-2002 06:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration