Is there a way to use bash to remove the last four columns for some input CSV file? The last four columns can have fields that vary in length from line to line so it is not sufficient to just delete a certain number of characters from the end of each row.
相关问题
- sqlyog export query result as csv
- JQ: Select when attribute value exists in a bash a
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
相关文章
- Check if directory exists on remote machine with s
- How to read local csv file in client side javascri
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- Symfony : Doctrine data fixture : how to handle la
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
rev
reverses the lines, so it doesn't matter if all the rows have the same number of columns, it will always remove the last 4. This only works if the last 4 columns don't contain any commas themselves.This might work for you (GNU sed):
awk one-liner:
the advantage of using awk over cut is, you don't have to count how many columns do you have, and how many columns you want to keep. Since what you want is removing last 4 columns.
see the test:
This awk solution in a hacked way
or alternatively
will drop the last 4 columns from each line.
Cut can do this if all lines have the same number of fields or awk if you don't.
Will print out the first 6 fields if you want to control the output seperater use --output-delimiter=string
Loops over fields up to th number of fields -4 and prints them out.