LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Text file manipulation: selecting specific lines/columns using awk and print (https://www.linuxquestions.org/questions/linux-newbie-8/text-file-manipulation-selecting-specific-lines-columns-using-awk-and-print-791472/)

CHARL0TTE 02-25-2010 06:20 AM

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

pixellany 02-25-2010 06:33 AM

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


CHARL0TTE 02-27-2010 02:40 AM

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!


All times are GMT -5. The time now is 04:24 PM.