My file (FILE1) looks like this:
HiringManager_RHMC, DirectSupervisor_RHMC, ProcessServerReadAccess_ST
I'd like to turn into:
HiringManager_RHMC
DirectSupervisor_RHMC
ProcessServerReadAccess_ST
I tried awk -F, '{print $1 $3}' FILE1
and result as this:
HiringManager_RHMC ProcessServerReadAccess_ST
Thank you in advance!
Hi,
If you're wanting to print the separate fields of a CSV out one per line, then something like this would work:
$ cat test.csv
HiringManager_RHMC,DirectSupervisor_RHMC,ProcessServerReadAccess_ST
$ awk -F, '{print $1"\n"$2"\n"$3}' < test.csv
HiringManager_RHMC
DirectSupervisor_RHMC
ProcessServerReadAccess_ST
$
Hope this helps - if it doesn't quite work for you then if you can let us know what doesn't work I'm sure we can help further.
1 Like
echo 'HiringManager_RHMC, DirectSupervisor_RHMC, ProcessServerReadAccess_ST' | awk -F, '$1=$1' OFS='\n'
1 Like
RudiC
February 19, 2020, 5:53pm
4
Not sure this works with all tr
versions:
echo "HiringManager_RHMC, DirectSupervisor_RHMC, ProcessServerReadAccess_ST" | tr -s ', ' '\n'
HiringManager_RHMC
DirectSupervisor_RHMC
ProcessServerReadAccess_ST
tr --version
tr (GNU coreutils) 8.30
2 Likes
rudic:
Not sure this works with all tr
versions:
echo "HiringManager_RHMC, DirectSupervisor_RHMC, ProcessServerReadAccess_ST" | tr -s ', ' '\n'
HiringManager_RHMC
DirectSupervisor_RHMC
ProcessServerReadAccess_ST
tr --version
tr (GNU coreutils) 8.30
Does not work with all tr versions, because each character,range,class in arg1 should match a character,range,class in arg2.
The following is portable:
echo "HiringManager_RHMC, DirectSupervisor_RHMC, ProcessServerReadAccess_ST" | tr -s ', ' '\n\n'
The tr substitutes each space or comma, regardless where they occur.
The following sed script takes a " ,
" (two character) delimiter; a single comma or space remains.
echo "HiringManager RHMC, DirectSupervisor RHMC, Process,ServerReadAccess_ST" | sed 's/, /\
/g'
HiringManager RHMC
DirectSupervisor RHMC
Process,ServerReadAccess_ST
GNU sed takes \n
in the substitution string, so you can do
echo "HiringManager RHMC, DirectSupervisor RHMC, Process,ServerReadAccess_ST" | sed 's/, /\n/g'