Computing.Net > Forums > Unix > duplicate line in middle of file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

duplicate line in middle of file

Reply to Message Icon

Name: killa watt
Date: June 27, 2003 at 11:11:56 Pacific
OS: unix (cygwin)
CPU/Ram: 2.4 / 500
Comment:

i am simply trying to search a file for a specific line, and then duplicate that line immediately after the original - and print the entire file out to another file.

it seems like it should be so simple, but i have tried everything i can think of.

i tried to grep the line using -n to list the line # where it is in the file - and then cut the number into another file - so i have the number 86 in a file. i then used a while loop with x=$((x + 1)) to sed each line into a seperate file - and then when x=86, and matches what's in the file containing 86 - append the line. obviously this is wrong - there must be a very simple way - can anyone help?

here is what i was trying to do...

(the line i want to copy starts with "PS1")


grep '^PS1.*$' profile > words
grep -n '^PS1.*$' profile > line
cut -c1,2 line > num
x=1

echo $x > xx

while test xx != num

do
sed -n "$x,1p" profile >> file.txt

x=$((x + 1))

echo $x > yy

cut -c1,2 yy > xx

done

i know the problem is that i can't test a file against another file - but i can't seem to get the 86 from those files into variables.

i'm just starting out - and any help would be greatly appreciated! i know there must be an easier way.



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: June 27, 2003 at 12:12:06 Pacific
Reply:

sed '/^PS1/p' profile > file.txt


0

Response Number 2
Name: killa watt
Date: June 27, 2003 at 18:42:08 Pacific
Reply:

WOW! I really suck.

thank you for humoring me and saving me from my ignorance.


0

Response Number 3
Name: James Boothe
Date: June 28, 2003 at 06:22:41 Pacific
Reply:

It was obvious that you "did your time" on this one. Actually, I was impressed by your thought processes. When you get the hang of everything - stand back out of the way everybody!  :-D


0

Response Number 4
Name: killa watt
Date: June 30, 2003 at 14:09:31 Pacific
Reply:

thanks - that does make me feel quite a bit better!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Shutdown remotely by a sc... 'no os'



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: duplicate line in middle of file

to remove duplicate lines from file www.computing.net/answers/unix/to-remove-duplicate-lines-from-file/7011.html

removing CR in middle of eachrecord www.computing.net/answers/unix/removing-cr-in-middle-of-eachrecord/5131.html

remove top line in file www.computing.net/answers/unix/remove-top-line-in-file/4769.html