I have TSV file like this:
abc_1
def_2
ghi_3
jkl_4
mno_5
I want to split that in to the:
abc
def
ghi
jkl
mno
and
1
2
3
4
5
How I can get that?
I have TSV file like this:
abc_1
def_2
ghi_3
jkl_4
mno_5
I want to split that in to the:
abc
def
ghi
jkl
mno
and
1
2
3
4
5
How I can get that?
With
awk
:Method 1
Split by character position:
To obtain the first output (here, the output is redirected to a file called first_output) use:
To obtain the second output use:
Here, the option
-c
means "select only the characters specified." The list following the option-c
specifies the character positions or ranges (where1
is the first character in the line).Method 2
Split according to delimiter:
Here, the option
-d
indicates the delimiting character (_
in our case) and the option-f
indicates field position to select.