1825768 Members
2101 Online
109687 Solutions
New Discussion

Re: Script

 
SOLVED
Go to solution
Prashant Zanwar_2
Occasional Advisor

Script

Hi,

I have a file which is having 1000 Line text.

1st line is header line.

I want to make an another file using this file adding some text "A" in beginning of each line avoiding header.

I want to automate this through the script. I want to provide file as input to the script.

Please reply immediate, as this is some urgent requirement.

Thanks in advance

Regards
Prashant
6 REPLIES 6
Chris Wilshaw
Honored Contributor
Solution

Re: Script

Using awk;

awk '{if (NR == 1) {print} else {print "EXTRA"$0}}' FILE

eg if your file contains

HEADER
BODY
BODY
BODY

The above awk will generate

HEADER
EXTRABODY
EXTRABODY
EXTRABODY
Marvin Strong
Honored Contributor

Re: Script


with perl you can do

$perl -pale 'next if ($. == 1); s/^/new/g' file1 > file2

This skips the first line, adds new to the beginning of the rest of the lines. And
creates file2.



Prashant Zanwar_2
Occasional Advisor

Re: Script

Hi,

Suppose I want to put a soecial charcter ";" which is not happening, after EXTRA, please reply.

Thanks and regards
Prashant
RAC_1
Honored Contributor

Re: Script

awk '{if (NR == 1) {print} else {print "EXTRA;"$0}}' FILE

Courtesy Chris.

Anil
There is no substitute to HARDWORK
Chris Wilshaw
Honored Contributor

Re: Script

Just a change to the previous awk;

awk '{if (NR == 1) {print} else {print "EXTRA;"$0}}' FILE
Prashant Zanwar_2
Occasional Advisor

Re: Script

Really really thankful for this brilliant response.

Thanks and regards
Prashant