Reputation: 103
After executing some commands in shell I am getting the output as below,
file1.txt@@/main/v1/v2/v3/v4/v5/v6/v7/v8/v9/v10/5
file2.txt@@/main/v4/v5/v6/v7/v8/v9/v10/4
file3.txt@@/main/v9/v10/8
Please tell me which commands I can apply to get the final output as below, simply the file name and the last 5 characters in each line
file1.txt v10/5
file2.txt v10/4
file3.txt v10/8
Upvotes: 1
Views: 61
Reputation: 43
Using awk:
awk -F'@@' '{print $1, substr($2, length($2)-4)}' filename
Upvotes: 0
Reputation: 41456
Using awk
awk -F"[@/]" '{print $1,$(NF-1)"/"$NF}' file
file1.txt v10/5
file2.txt v10/4
file3.txt v10/8
Separate text using @
and /
, print first field, second last field and last field.
If tab is needed:
awk -F"[@/]" '{print $1"\t"$(NF-1)"/"$NF}' file
file1.txt v10/5
file2.txt v10/4
file3.txt v10/8
Upvotes: 4
Reputation: 97938
Add this at the end of your pipeline:
sed 's!@@.*/\([^/]*/[^/]*$\)!\t\1!'
Upvotes: 0