Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-25-2010, 07:20 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 14

Rep: Reputation: 0
Text file manipulation: selecting specific lines/columns using awk and print


hopefully someone can help. I have a large number of text files which I need to combine into a single file, but I'm stuck on a simple bit. Each text file is in an identical format. I just need to extract everything in columns 1 and 2 (which I can do) but only lines 164-201 (this is the bit I'm stuck on).

I have gotten as far as:

cat mytextfile_??.txt | awk '{print $1,$2}' > mynewtextfile.txt

Can anyone advise how I specify the range of lines to print from and to?

Many thanks,

Old 02-25-2010, 07:33 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741
To clarify:
You want lines 164-201 (inclusive) from each file, and only the contents of columns 1 and 2. Then you want the files combined in sequence?

Suppose all the files are in one directory, with nothing else present:

for filename in *; do
    sed -n '164,201p' $filename | awk '{print $1, $2}'
done >> newfile
1 members found this post helpful.
Old 02-27-2010, 03:40 AM   #3
LQ Newbie
Registered: Jul 2009
Posts: 14

Original Poster
Rep: Reputation: 0
SOLVED: Text file manipulation: selecting specific lines/columns using awk and print

Hi Pixellany

thank you. That seems to work as I wanted.


NB, I keep trying to thank the people who help me on here using the 'thank icon' but it never seems to work!


awk, print

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
Text file manipulation: Extracting specific rows according to numerical pattern CHARL0TTE Linux - Newbie 3 10-07-2009 08:14 AM
awk print correct lines when certain columns are blank schneidz Programming 11 04-04-2008 05:06 PM
Replacing text on specific lines with sed or awk? Lantzvillian Linux - Newbie 5 10-17-2007 10:00 AM
Read specific lines from a text file chobin Programming 8 06-14-2006 12:14 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:10 PM.

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