Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread 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
Sponsored Links
  #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>

  #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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0