The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 06:19 AM
extract a line from a file using the line number grandtheftander Shell Programming and Scripting 6 02-06-2008 02:12 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-20-2007 09:29 PM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 01:34 PM
identifying duplicates line & reporting their line number stresslog UNIX for Dummies Questions & Answers 5 04-23-2006 09:43 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-12-2008
Ezy Ezy is offline
Registered User
 

Join Date: Feb 2008
Posts: 5
Post Adding a columnfrom a specifit line number to a specific line number

Hi,

I have a huge file & I want to add a specific text in column. But I want to add this text from a specific line number to a specific line number & another text in to another range of line numbers.

To be more specific: lets say my file has 1000 lines & 4 Columns. I want to add text "Hello" to 5th column but from line 1 to line 200. & I want to add another text "goodbye" to 5th column of the same file from line 201 to 800 & another text "live" again to 5th column to the same file from line 801 to 1000.

I know I can use sed to add a column to my file but I don't know how to tell sed to add this column to from line & to to line.


Code:
$ sed 's/\(.*\) \(.*\) \(.*\) \/\1 \2 \3 \  Desired string/' input > output
this will add my desired string to the 4th column in the right place but I don't know how to limit this to a specific range of lines.

May be there is a way to do it in sed or may be awk?

Any help will be very welcome.

Thanks in advance,
Ezy
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
Code:
awk ' NR >=1 && NR <= 200 { print $0 " Hello" }
        NR >=201 && NR <=800 { print $0 " Goodbye"}
        NR >=801 && NR <=1000 { print $0 " live"}' <filename>
Reply With Quote
  #3 (permalink)  
Old 05-12-2008
Ezy Ezy is offline
Registered User
 

Join Date: Feb 2008
Posts: 5
Post works perfectly fine

Oh thanks a lot....this works perfectly fine & it seems fast enough to work with huge files.

Thanks a lot
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0