output lines in place of columns
Hello everyone,
I want to output data in row rather than in column after having selected a pattern from a list with awk. But the command output truncated data, The original file: Code:
head -3 file.txt Code:
cat list.txt | while read line ; Code:
5_1009.7 1_1011 Would anyone know how to avoid it? |
Code:
cat list.txt | cut -f3 | tr '\n' '\t' |
Try this:
awk '{ print $3 "\n" }' < file.txt |
From https://www.gnu.org/software/gawk/ma...hell-Variables
Code:
printf "Enter search pattern: " Code:
printf "Enter search pattern: " |
Make awk remove a WinDOS CR (also represented as ^m or \r).
Code:
while read line |
what is in list.txt ?
|
My mistake not to have indicated the content of list.txt pan64. They were the headers of the file.txt.
Thank you Allend and MadeInGermany. These version of the script work perfectly. I am not familiar with some of the syntax you have used for this answer. I will have a closer look to your script. |
so maybe:
Code:
grep -f list.txt file.txt | awk '{ print $3 }' |
Following the idea from MadeInGermany, I would like to revise my suggestion.
Code:
awk -v pat="$pattern" '$0 ~ pat {printf dl$3; dl="\t"};END {printf "\n"}' file.txt |
Thanks a lot pan64 and allend!
The subject has been marked as solved, but actually, it is not. I think there is a problem with the format of my dataset rather than the scripts that have been posted. I have tried with your last command allend, and it does not work either. I guess I have to spend more time working with awk...again! I wish as well to understand this simple command I was using routinely does not work in this case. It is puzzling. Quote:
|
would be nice to explain exactly what did you try, what did not work (and how), and what do you wish exactly.
Probably a better example can help too. |
Attention: a variable having an unknown value should not appear in the format string (first arg of printf or sprintf); the characters % and \ are interpreted in a special way.
Unsafe: Code:
printf dl$3 Code:
printf "%s%s", dl, $3 Code:
printf (dl "%s"), $3 |
Thanks much for your patience.
I will take another example on this set of data, which illustrate better the problem. I have files like this one: Quote:
Quote:
Quote:
|
what kind of visual errors ?
Code:
grep -f list.txt file.txt | awk '{ printf $3"\t" }' |
The characters "Becon104" are printed in the left corner of the terminal, just before my usr:/path identifier. And there is no output.
It is almost like the output are printed, but covered by my usr:/path. |
All times are GMT -5. The time now is 05:12 AM. |