Operating System - HP-UX
1753464 Members
4819 Online
108794 Solutions
New Discussion юеВ

Adding new "column" into a txt file

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

Adding new "column" into a txt file

Hi,
I have a txt file which has the following form:
#cat myFile.txt
nwd.256.cr
nwd.sfv.67
nwd.tty.pp
... (& so on, all in vertical order)

I would like to add the pattern /fs36/ at the front of all the entries in myFile.txt.

Is there a utility which allows me to insert a pattern at the begining or anywhere in a file?
If so, could anyone provide some examples?

Thanks.
4 REPLIES 4
Michael Tully
Honored Contributor
Solution

Re: Adding new "column" into a txt file

Try this:

vi your file:

in command mode:
:1,$s/^/\/fs36\//g

This should do it...

HTH
~Michael~
Anyone for a Mutiny ?
Sridhar Bhaskarla
Honored Contributor

Re: Adding new "column" into a txt file

Hi,

The utility by default available on unix systems is sed.

sed 's/^/\/fs36\//g' myFile.txt > new_file

To append at the end replace ^ with $ in the above command.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Patrick Wallek
Honored Contributor

Re: Adding new "column" into a txt file

As with everything else in unix there are multiple ways to do this.

You could also use awk. Something like this should work, although I can't guarantee it since I'm not at a machine I can test on.

# awk '{ print "/fs36/" $0 }' yourfile.txt > your_new_file.txt

chin hyeon jung
Advisor

Re: Adding new "column" into a txt file

First open the file using vi
and then
:1,$s/^/fs36 /g
You can get what you want