Posts

Showing posts with the label awk

How do I convert key value paired list into table with columns using AWK?

How do I convert key value paired list into table with columns using AWK? I need to convert a dataset from a key value paired list (informix dbaccess output) into a columned csv. I'm fairly certain this can be done easily with awk or sed. UPDATE The solution needs to be a single line response. I am using NSH (which is based on ZSH). So some of the typical "bashy" commands will not work. Here is my data sample set: part_no 100000001 date_part 2010-10-13 12:12:12 history_code ABCD user_id rsmith other_information note: Monday, December 10 pool_no 101011777 part_no 100000002 date_part 2010-10-21 12:12:12 history_code GHIJ user_id jsmith other_information pool_no 101011888 part_no 100000002 date_part 2010-10-27 12:12:12 history_code LMNO user_id fevers other_information [Mail] pool_no 101011999 part_no 100000003 date_p...

Reformat data using awk

Reformat data using awk I have a dataset that contains rows of UUIDs followed by locations and transaction IDs. The UUIDs are separated by a semi-colon (';') and the transactions are separated by tabs, like the following: 01234;LOC_1=ABC LOC_1=BCD LOC_2=CDE 56789;LOC_2=DEF LOC_3=EFG I know all of the location codes in advance. What I want to do is transform this data into a format I can load into SQL/Postgres for analysis, like this: 01234;LOC_1=ABC 01234;LOC_1=BCD 01234;LOC_2=CDE 56789;LOC_2=DEF 56789;LOC_3=EFG I'm pretty sure I can do this easily using awk (or similar) by looking up location IDs from a file (ex. LOC_1) and matching any instance of the location ID and printing that out next to the UUID. I haven't been able to get it right yet, and any help is much appreciated! My locations file is named location and my dataset is data . Note that I can edit the original file or write the results to a new file, either is fine. location data ...

Print file count owned by a given user

Print file count owned by a given user How to print the number of files owned by every user in a given directory? So far I am printing user name and disk size. However I want to report out the output of " find $dirname -user <user_name>| wc -l " and print that as a third field in the below printf find $dirname -user <user_name>| wc -l set dirname = "a/b/c" find $dirname -printf "%u %sn" 2 Answers 2 I have a feeling you want to do something like this : find $dirname -printf "%u %sn" | awk '{s[$1]+=$2;c[$1]++}END{for(u in s) print u,s[u],c[u]} This will print a list of users with total accumulated file-size and the total amount of files. Exactly what I was trying to get at! Did a lot of circus and foreach loops with find <dir_name> -user <user_name | wc -l followed by saving the contents into an array. Ev...

How to execute an awk call with mixed quotes in R?

How to execute an awk call with mixed quotes in R? I need to run awk from within R to add spaces at the end of each line of a file, to ensure that it has consistently a fixed width throughout. Like this: awk $ cat -e file 1$ 12$ 123$ 1234$ $ awk '{printf "%-10sn", $0}' file | cat -e 1 $ 12 $ 123 $ 1234 $ 12345 $ However I have trouble doing this from within R. How to correctly escape system calls from inside R deals with something similar, but it doesn't seem to work for me. > ' awk '{printf "%-180sn", $0}' file ' [1] " awk '{printf "%-180sn", $0}' file " > system(' awk '{printf "%-180sn", $0}' file ') awk: cmd. line:1: {printf "%-180s awk: cmd. line:1: ^ unterminated string awk: cmd. line:1: {printf "%-180s awk: cmd. line:1: ^ syntax error I also tried system(" awk '{printf "%-180sn", $0}' file ...