Answer the question
In order to leave comments, you need to log in
Bash - how to display only the first word?
Good afternoon. Please help me figure this out: I have a command that filters a message
echo `less 1634886389/executed2_6690.txt | awk -F"#" '{print $2}'`
674256 10745127/2 name
674262 10745127/3 name
674268 10745127/4 name
674274 10745127/5 name
674280 10745127/6 name
#674256 10745127/2 name #674262 10745127/3 name #674268 10745127/4 name #674274 10745127/5 name #674280 10745127/6 name
Answer the question
In order to leave comments, you need to log in
Initially, the string is very long, but I only need to pull out the value 674256, 674262, etc. from it. so that they are without the # sign and each on a new line - in the original they are with the # sign
$ echo "#674256 10745127/2 name #674262 10745127/3 name #674268 10745127/4 name #674274 10745127/5 name #674280 10745127/6 name" | awk 'BEGIN{RS="#"}{print $1}'
674256
674262
674268
674274
674280
The cut command will help to pull the first column:
cut -f 1 -d ' '
add it to the end of the main command
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question