0

I have about 50 files in a directory

Have

File1: 1|2|3

File2: 3|4|5

File3: A|B|C 

WANT

File1: A|1|2|3

File2: A|3|4|5

File3: A|A|B|C 

I'll appreciate if anyone can solve it with awk command. I'm open to other solutions in linux. Also, I want to run it once an perform edits on all files in a directory.

The solution (see below) I have will require me to run it on each file one at a time and I don't think that's efficient

awk '{print "A|"$0}' File1 
Ashish K
  • 905
  • 10
  • 27
user2008558
  • 341
  • 5
  • 16
  • 2
    You've already solved it with awk. Now you just need to loop through each file in the directory. http://stackoverflow.com/questions/20796200/how-to-iterate-over-files-in-directory-with-bash – JNevill Oct 14 '14 at 18:18

2 Answers2

2

Try the below sed command,

sed -i 's/^/A|/' file1 file2 file3

To make it work on all the files in the current directory,

sed -i 's/^/A|/' *
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
1

With GNU awk for -i inplace:

gawk -i inplace '{print "A|"$0}' file1 file2 file3
Ed Morton
  • 188,023
  • 17
  • 78
  • 185