![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to insert text in the middle of a file | kartikkumar84@g | UNIX for Dummies Questions & Answers | 6 | 05-10-2008 11:35 AM |
| insert text in the middle of a file | relle | Shell Programming and Scripting | 3 | 03-13-2008 12:37 PM |
| How to insert the 1st arg into the middle of the file | boris | Shell Programming and Scripting | 4 | 04-12-2007 09:21 PM |
| How to insert text into first line of the file and middle of the file? | ali hussain | Shell Programming and Scripting | 3 | 03-05-2007 02:54 AM |
| insert text into the middle of a original file | mopimp | Shell Programming and Scripting | 1 | 03-26-2006 07:11 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to insert one file into another file not by concatenating as usual done.
file1 A B C D E F G H I J K L file2 23455 33444 33334 33345 Output shud be 23455 A B C D 33444 E F G H 33345 I J K L |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
probably an easier way than this, but it does work :
Code:
# paste -s -d "\t\n" file1 | paste file2 - | tr "\t" "\n" 23455 A B C D 33444 E F G H 33334 I J K L 33345 |
|
#3
|
||||
|
||||
|
also - can use cat for legibility:
Code:
# cat file1 | paste - - | paste file2 - | tr "\t" "\n" |
|
#4
|
|||
|
|||
|
33334
I J K L 33345 [/code][/quote] Thanks..... Last edited by cdfd123; 03-07-2008 at 05:05 AM. Reason: just thanks |
|
#5
|
|||
|
|||
|
Code:
awk 'FNR==NR{ a[FNR]=$0;next }
{
print $0
print a[FNR+l]
l++
print a[FNR+l]
}
' file file1
Code:
# ./test.sh 23455 A B C D 33444 E F G H 33334 I J K L 33345 |
|||
| Google The UNIX and Linux Forums |