2 (two) here documents in a row


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers 2 (two) here documents in a row
# 1  
Old 10-29-2010
2 (two) here documents in a row

Ok, it may sound a bit stupid but I can't find the answer.. How do one put 2 here documents in a row? for instance, i want to do something like:

Code:
diff <<eof <<eof2 # doesn't work...
> a
> b
> eof
> a
> c
> eof2

its mostly to satisfy my curiosity!!
thanks,
Anthony
# 2  
Old 10-29-2010
This should work with ksh (ksh93 at least)
Code:
diff <(cat <<eof
a
b
eof) <(cat <<eof
a
c
eof)

# 3  
Old 10-29-2010
If you haven't got the above Shell, then you need to use workfiles.
For example:
Code:
file1=/tmp/file1.$$
file2=/tmp/file2.$$
#
cat <<eof >${file1}
a
b
eof
#
cat <<eof >${file2}
a
c
eof
#
diff ${file1} ${file2}
#
rm ${file1}
rm ${file2}

# 4  
Old 10-29-2010
I just noticed my code works with bash too but need a small modification to work there (eof and closing parenthesis on a different line):

Code:
diff <(cat <<eof
a
b
eof
) <(cat <<eof
a
c
eof
)

This User Gave Thanks to jlliagre For This Post:
# 5  
Old 10-29-2010
I see, I use bash too. that might come handy one day!
Thanks guys Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

This is a question that is related to one I had last August when I was trying to sort/merge two files by millsecond time column (in this case column 6). The script (below) that helped me last august by RudiC solved the puzzle of sorting/merging two files by time, except it gets lost when the... (0 Replies)
Discussion started by: aachave1
0 Replies

2. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

3. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

My original files are like this below and I distinguish them from the AP_ID (file1 has 572 and file2 has 544). Also, the header on file1 has “G_” pre-pended. NOTE: these are only snippets of very large files and much of the data is not present here. Original File 1: ... (36 Replies)
Discussion started by: aachave1
36 Replies

4. Shell Programming and Scripting

Add Row from First Row (Split Row)

HI Guys, I have Below Input :- RepigA_hteis522 ReptCfiEtrBsCll_aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 RepigA ReptCfiEtrBsCll hteis522 aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 Split Data in two first row... (2 Replies)
Discussion started by: pareshkp
2 Replies

5. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

6. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

7. UNIX for Dummies Questions & Answers

LPD and sophisticated documents

Hi all, I am using Solaris 8 and have several printers (HP lasers or inkjets) connected behind PCs, printing thus being controlled by LPD. All I can print is ASCII, not very keen, no images, no boxes etc. Is there any thread (I assure, I have been searching!) or discussion explaning how to set... (0 Replies)
Discussion started by: nulnul7
0 Replies

8. Solaris

sudo documents

I have installed sudo on our development server (SPARC,Solaris 9) and trying to edit /etc/sudoers file using visudo. Referred the following sites and not able to find the way. http://www.courtesan.com/sudo/man/sudoers.html http://www.kempston.net/solaris/sudo.html To start with sudo, my... (3 Replies)
Discussion started by: chrs0302
3 Replies

9. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question