This is a testI want my input file with the following output:
Giving back more than we take
a testHow do I printing lines from the nth field using awk under UNIX or Linux operating systems?
more than we take
You can use the awk command as follows:
OR
echo 'This is a test' | awk '{print substr($0, index($0,$3))}'
You can also use the cut command:
awk '{print substr($0, index($0,$3))}' <<< 'This is a test'
OR
echo 'This is a test' | cut -d ' ' -f3-
Finally, process the file using bash while loop:
cut -d ' ' -f3- <<<'This is a test'
#!/bin/bashPlease note that you can also use Perl, Python or other shell text processing commands to do the same thing.
_input="/path/to/file.name.txt"
while IFS= read -r line
do
cut -d ' ' -f3- <<<"$line"
### same stuff with awk ###
### awk '{print substr($0, index($0,$3))}' <<< "$line" ###
done < "${_input}"
No comments:
Post a Comment