Reputation: 152
Input is a tab-separated file (here spaces but whatever):
Sample1 ACGGGGCGCAGCAGGCGCGA text other122
something ABCDSDDADASDASDSAD hjas 23823sss
ahsdksads AHJHJDHSJHJDALKDLK hello world
What I want to do is to add a column of tabs after the first column. So basically:
Sample1<TAB><TAB>ACGGGGCGCAGCAGGCGCGA<TAB>text<TAB>other122
something<TAB><TAB>ABCDSDDADASDASDSAD<TAB>hjas<TAB>23823sss
ahsdksads<TAB><TAB>AHJHJDHSJHJDALKDLK<TAB>hello<TAB>world
sed/awk preferred but whatever goes..
Upvotes: 0
Views: 1678
Reputation: 10683
Pure bash solution:
filename='file.txt'
tempFile="/tmp/my_script_$RANDOM"
while read -r line; do
printf "%s\n" "${line/ / }" >> "$tempFile" # should be ${line/<TAB>/<TAB><TAB>}
done < "$filename"
mv -f -- "$tempFile" "$filename"
Upvotes: 0
Reputation: 58324
Since you want two tabs after the first column:
sed 's/\([^ \t]*\) \([^ \t]*\)/\1\t\2/g' foo.txt | sed 's/\t/\t\t/'
Upvotes: 0
Reputation: 58578
This might work for you (GNU sed):
sed 's/\t/&&/' file
or:
awk '{sub(/\t/,"&&")}1' file
Upvotes: 3
Reputation: 290525
What about this?
$ awk 'BEGIN{OFS=FS="\t"} $2="\t"$2' file
Sample1 ACGGGGCGCAGCAGGCGCGA text other122
something ABCDSDDADASDASDSAD hjas 23823sss
ahsdksads AHJHJDHSJHJDALKDLK hello world
Which is exactly the same as awk 'BEGIN{OFS=FS="\t"} $1=$1"\t"'
. That is, it either appends one tab to the end of 1st field or to the beginning of the 2nd one.
Also
$ awk 'BEGIN{OFS=FS="\t"} $2=FS$2' file
Upvotes: 1
Reputation: 4974
You change the output field seperator to a tab, and and an extra tab after the first element:
awk -v 'OFS=\t' '$1=$1"\t"'
Upvotes: 0