Posts

Showing posts with the label sed

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 ...

Sed with Regexp not working?

Sed with Regexp not working? I'm trying to search in all files a text and replace it with the word EXAMPLE. I do the following: for f in /home/testu/zz*; do sed -i "s/&VAR1s*=s*'?[1]{4}'?/EXAMPLE/g" "$f" done It gives no error, the files seems to be "updated" in the filesystem, but they wont get changed. If I test that regexp with grep command it works fine, so it must be something about the regexp with the sed command but dunno what. Any help? Are you aware that [1]{4} matches 1111 ? Is that your intention? – Wiktor Stribiżew Jun 29 at 8:14 [1]{4} 1111 Ah, use sed -i "s/&VAR1s*=s*'?1{4}'?/EXAMPLE/g" or sed -i "s/&VAR1[[:blank:]]*=[[:blank:]]*'?1{4}'?/EXAMPLE/g" – Wiktor...