print line 1 of each file, line 2 of each file...

print line 1 of each file, line 2 of each file...

Post by Dan Jacobso » Tue, 09 Apr 2002 00:30:53



How do I print

Line 1 of file A
Line 1 of file B
Line 1 of file C

Line 2 of file A
Line 2 of file B
Line 2 of file C
...?

Currently I use
paste -d X A B C|awk '{gsub("X","\n");print;print ""}'
but I feel like a jerk.
--
http://jidanni.org/ Taiwan(04)25854780

 
 
 

print line 1 of each file, line 2 of each file...

Post by laura fairhe » Wed, 10 Apr 2002 08:46:53



Quote:>How do I print

>Line 1 of file A
>Line 1 of file B
>Line 1 of file C

>Line 2 of file A
>Line 2 of file B
>Line 2 of file C
>...?

>Currently I use
>paste -d X A B C|awk '{gsub("X","\n");print;print ""}'
>but I feel like a jerk.

You can use the special deliminator \n to make each line
seperated by a newline, then as your last file just use
the NUL device so that an extra newline gets appended;

paste -d '\n' A B C /dev/null

Other useful standard special deliminators in the 'paste'
command are \t and \0.

Quote:>--
>http://jidanni.org/ Taiwan(04)25854780

regards

--

                # if you are bored crack my sig.
1F8B0808CABB793C0000666667002D8E410E83300C04EF91F2877D00CA138A7A
EAA98F30C494480157B623C4EF1B508FDED1CEFA9152A23DE35D661593C5318E
630C313CD701BE92E390563326EE17A3CA818F5266E4C2461547F1F5267659CA
8EE2092F76C329ED02CA430C5373CC62FF94BAC6210B36D9F9BC4AB53378D978
80F2978A1A6E5D6F5133B67B6113178DC1059526698AFE5C17A5187E7D930492

 
 
 

1. Search file and print line + next line?

Hello,

I have a file which has lines organized as such:

------------------
TITLE1 plus some other junk
This is some information about title 1 (one line)

TITLE2 plus some other junk
This is some information about title 2 (one line)

TITLE3 plus some other junk
This is some information about title 3 (one line)
------------------

I would like to be able to search for TITLE1 and have it print out the line
with TITLE1 in it (may not be alone on the line) , _plus_ the following line.

Is AWK the appropriate language to do this in, or can it be done with
GREP or SED?

As a generic extension, a secondary desire is to print out the next 'n' lines
instead of just the next one. But one is manditory.

Thanks,

        Steven

--
                                From the desk of:
                                        Steven Christensen   N9XJY

2. How to attach a driver to PCMCIA memory?

3. how to append one file's line to another file's line?

4. a good sound player

5. one liner which prints n lines before and m lines after the line found by grep

6. OnStream tape drive

7. How to read line by line of a file

8. router with to network interfaces

9. HELP: How do I read a file line-by-line without getting spaces stripped?

10. read a file line by line

11. How to read line by line from a file?

12. select line from file, and then the next line a week later

13. Line wrap file > 80 lines