B
B
bashlaevs2021-10-22 13:53:09
bash
bashlaevs, 2021-10-22 13:53:09

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}'`

where I search by the separator # and actually output the data to the console (for readability, I split it into columns, and in general it displays everything to me in one line)
674256 10745127/2 name 
674262 10745127/3 name 
674268 10745127/4 name 
674274 10745127/5 name 
674280 10745127/6 name

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
#674256 10745127/2 name #674262 10745127/3 name #674268 10745127/4 name #674274 10745127/5 name #674280 10745127/6 name

The question is - how can I make it so that I can only output the value from the first column and write it to the file, provided that it is not the only word with the # sign in the source?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xotkot, 2021-10-22
@bashlaevs

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

U
unseriously, 2021-10-22
@unseriously

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 question

Ask a Question

731 491 924 answers to any question