how to insert character at the beginning of each line in a file 
Author Message
 how to insert character at the beginning of each line in a file

Hi all,

I would like to know how to insert a character at the beginning of each
line in a file.

Let's say I have a file with the following info:

line1
line2
line3
line4

... and so on

Say, I want to put a > sign in front of each line as such

Quote:
> line1
> line2
> line3
> line4

I've read the man pages and tried many different options to no avail.  I've
found another way to achieve this but I am curious to know how to do this
with Awk.
Thanks in advance


Wed, 20 Aug 2003 02:09:12 GMT  
 how to insert character at the beginning of each line in a file
...
| Let's say I have a file with the following info:
|
| line1
| line2
...
| Say, I want to put a > sign in front of each line as such
|
|> line1
|> line2
...

Easiest:  awk '{ print ">" $0 }' inputfile



Tue, 19 Aug 2003 15:52:29 GMT  
 how to insert character at the beginning of each line in a file

: Hi all,

: I would like to know how to insert a character at the beginning of each
: line in a file.

: Let's say I have a file with the following info:

: line1
: line2
: line3
: line4

: ... and so on

: Say, I want to put a > sign in front of each line as such

:> line1
:> line2
:> line3
:> line4

: I've read the man pages and tried many different options to no avail.  I've
: found another way to achieve this but I am curious to know how to do this
: with Awk.
: Thanks in advance

Hello,

   Try this:

awk '{print "> " $0}' file_name >new_file_name

Jim



Sat, 23 Aug 2003 06:07:46 GMT  
 how to insert character at the beginning of each line in a file

Quote:

>: Hi all,
>: I would like to know how to insert a character at the beginning of each
>: line in a file.
>: Let's say I have a file with the following info:
>: line1
>: line2
>: line3
>: line4
>: ... and so on
>: Say, I want to put a > sign in front of each line as such
>:> line1
>:> line2
>:> line3
>:> line4
>: I've read the man pages and tried many different options to no avail.  I've
>: found another way to achieve this but I am curious to know how to do this
>: with Awk.

If you're just curious about using awk, that's cool.  But if you need to
do this now, vi would be able to this wht

:%s/^/>

:%   For the whole file
s    Substitue
/^   Beginning of the line
/>   With ">" char

hsb

"Somehow I imagined this experience would be more rewarding"  Calvin
********************************************************************
Due to the volume of email that I receive, I may not not be able to  
reply to emails sent to my account.  Please post a followup instead.
********************************************************************



Sat, 23 Aug 2003 07:58:29 GMT  
 how to insert character at the beginning of each line in a file

Quote:


>: Hi all,

>: I would like to know how to insert a character at the beginning of each
>: line in a file.

>: Let's say I have a file with the following info:

>: line1
>: line2
>: line3
>: line4

>: ... and so on

>: Say, I want to put a > sign in front of each line as such

>:> line1
>:> line2
>:> line3
>:> line4

>: I've read the man pages and tried many different options to no avail.  I've
>: found another way to achieve this but I am curious to know how to do this
>: with Awk.
>: Thanks in advance

>Hello,

>   Try this:

>awk '{print "> " $0}' file_name >new_file_name

>Jim

Or this, in Thompson AWK:

    !call("printf",">")

Bonus points if you can figure out why this works...



Sat, 23 Aug 2003 08:16:40 GMT  
 how to insert character at the beginning of each line in a file

Quote:

>Hi all,
>I would like to know how to insert a character at the beginning of each
>line in a file.

>Let's say I have a file with the following info:
>line1
>line2
>line3
>line4

>... and so on

>Say, I want to put a > sign in front of each line as such

>> line1
>> line2
>> line3
>> line4

awk '{print ">"$0}' file

--
To email, remove DELE



Sat, 23 Aug 2003 20:45:08 GMT  
 how to insert character at the beginning of each line in a file

<snip>

Quote:
>Or this, in Thompson AWK:

>    !call("printf",">")

>Bonus points if you can figure out why this works...

Congratulations! This makes perl look like a vision of clarity. Good work!

(When will we get a pr solution, I wonder?!)



Mon, 25 Aug 2003 00:40:57 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Insert characters at the beginning of a file.

2. Inserting text at the beginning of a line

3. Remove lines beginning with # from file

4. insert a character in ASCII File?

5. remove blank lines before lines beginning with string

6. inserting a blank line in a file

7. insert several lines into a ascii-file

8. Inserting a Line in a DBF file

9. insert line in middle of file

10. How to insert a line in a file?

11. Strip characters and lines from a text file

12. how to split each new line into a list, considering quoted new line characters

 

 
Powered by phpBB® Forum Software