- Prepare
- Linux Shell
- Text Processing
- Cut #5
- Discussions
Cut #5
Cut #5
+ 0 comments using '\t' doesn't work.
instead, use:
cut -d "$(printf '\x09')" -f 1-3
explenation:
something is wrong with this website or the input file.
x09 (x means: hexadecimal) is the ASCII hex value of the "tab" character. should be the same as '\t'. so we are telling printf to print the tab character.
then, by using $() (which is called "command substitution") we are taking the output of the command inside, which is the printed tab, and using it as the delimeter.
+ 0 comments while read str do echo "$str" | sed 's/\n/ /g' | tr " " "\n" >> txt done
readarray ARRAY < txt
for i in "{#i}-1 if [ i fi done
+ 0 comments while read line do echo "$line" | cut -f 1-3 done
+ 1 comment After a while trying... The key were the "double quotes" *
# Solution while read line; do echo "${line}" | cut -d $'\t' -f -3 done
+ 0 comments The test file isn't tab delimited. It may have been at one point, but no longer is as piping output to
od -c
shows NO TAB characters.0000140 1 5 , 9 0 0 1 N e w Y o r 0000160 k - N e w a r k - B r i d g e p 0000200 o r t , N Y - N J - C T - P A 0000220 C S A 2 2 , 2 1 4 , 0 8 3 \n 0000240
Sort 140 Discussions, By:
Please Login in order to post a comment