1
votes

I want to modify lines in a file using awk and print the new lines with the following line. My file is like this

Name_Name2_ Name3_Name4  
ASHRGSJFSJRGDJRG  
Name5_Name6_Name7_Name8  
ADGTHEGHGTJKLGRTIWRK

I want

Name-Name2  
ASHRGSJFSJRGDJRG   
Name5-Name6  
ADGTHEGHGTJKLGRTIWRK

I have sued awk to modify my file:

awk -F'_' {print $1 "-" $2} file > newfile

but I don't know how to tell to print also the line just after (ABDJRH)

sure is it possible with awk x=NR+1 NR<=x

thanks

2
Please clarify the statement "but I don't know how to tell to print also the line just after (ABDJRH)" once too? - RavinderSingh13

2 Answers

5
votes

Following awk may help you on same.

awk -F"_" '/_/{print $1"-"$2;next} 1'   Input_file
0
votes

assuming your structure in sample (no separation in line with "data" letter )

awk '$0=$1' Input_file

# or with sed
sed 's/[[:space:]].*//' Input_file