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

Notices


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

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


hi,

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,

Charlotte
 
Old 02-25-2010, 06:33 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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:

Code:
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, 02:40 AM   #3
CHARL0TTE
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.

Charlotte

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


Reply

Tags
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 07:14 AM
awk print correct lines when certain columns are blank schneidz Programming 11 04-04-2008 04:06 PM
Replacing text on specific lines with sed or awk? Lantzvillian Linux - Newbie 5 10-17-2007 09:00 AM
Read specific lines from a text file chobin Programming 8 06-14-2006 11:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:14 AM.

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