awk

Unix - Convert GMT time field to PST time

六眼飞鱼酱① 提交于 2021-01-27 19:05:27
问题 Sorry if this has been asked before. I have a text file that contain a field with GMT time on Unix. I want to convert that field to the PST time zone in the same format. source file test.txt 20200804T221806.214 GMT,2003060015,2003060018 20200804T232027.571 GMT,2005260045,2005260095 20200804T232027.572 GMT,2005260045,2005260095 20200805T000119.715 GMT,2005290022C,2005290042D 20200805T000119.715 GMT,2005290022C,2005290042D 20200801T000326.111 GMT,2005290028C,2005290050D 20200101T000326.111 GMT

Add line after matching a pattern [duplicate]

元气小坏坏 提交于 2021-01-27 14:09:48
问题 This question already has answers here : Using sed, Insert a line above or below the pattern? [duplicate] (4 answers) Closed 3 years ago . I have a file say test with following values Linux Solaris Fedora Ubuntu AIX HPUX How to add a line with system hostname after the line matching AIX? If I do echo `hostname` >> test system hostname comes at the last after HPUX. 回答1: With sed: sed "s/^AIX$/& $(hostname)/" file If the line could contain AIX : sed "s/AIX.*/& $(hostname)/" file Edit: To append

awk super slow processing many rows but not many columns

半世苍凉 提交于 2021-01-27 13:44:45
问题 While looking into this this question the challenge was to take this matrix: 4 5 6 2 9 8 4 8 m d 6 7 9 5 4 g t 7 4 2 4 2 5 3 h 5 6 2 5 s 3 4 r 5 7 1 2 2 4 1 4 1 9 0 5 6 d f x c a 2 3 4 5 9 0 0 3 2 1 4 q w And turn into: 4 5 m d t 7 h 5 r 5 4 1 x c 0 0 6 2 # top of next 2 columns... 6 7 4 2 ... each N elements from each row of the matrix -- in this example, N=2... 3 4 4 1 d f 5 9 q w # last element is lower left of matrix The OP stated the input was 'much bigger' than the example without

Read lines from a file, grep in a second file, and output a file for each $line

只愿长相守 提交于 2021-01-27 13:21:26
问题 I have the following two files: sequences.txt 158333741 Acaryochloris_marina_MBIC11017_uid58167 158333741 432 1 432 COG0001 0 158339504 Acaryochloris_marina_MBIC11017_uid58167 158339504 491 1 491 COG0002 0 379012832 Acetobacterium_woodii_DSM_1030_uid88073 379012832 430 1 430 COG0001 0 302391336 Acetohalobium_arabaticum_DSM_5501_uid51423 302391336 441 1 441 COG0003 0 311103820 Achromobacter_xylosoxidans_A8_uid59899 311103820 425 1 425 COG0004 0 332795879 Acidianus_hospitalis_W1_uid66875

AWK negative regular expression with variable

假如想象 提交于 2021-01-27 12:02:46
问题 I am using awk in a bash script to compare two files to get just the not-matching lines. I need to compare all three fields of the second file (as one pattern?) with all lines of the first file: First file: chr1 9997 10330 HumanGM18558_peak_1 150 . 10.78887 18.86368 15.08777 100 chr1 628885 635117 HumanGM18558_peak_2 2509 . 83.77238 255.95094 250.99944 5270 chr1 15966215 15966638 HumanGM18558_peak_3 81 . 7.61567 11.78841 8.17169 200 Second file: chr1 628885 635117 chr1 1250086 1250413 chr1

how to extract text which matches particular fields in text file using linux commands

蓝咒 提交于 2021-01-27 12:01:17
问题 Hi below is my text file {"Author":"john" "subject":"java" "title":"java cook book.pdf"} {"title":"Php book.pdf" "Author":"Smith" "subject":"PHP"} {"Author":"Smith" "title":"Java book.pdf"} from the above data i want to extract all titles which contains "java" word, i should get the following output java cook book.pdf Java book.pdf Please suggest me Thanks 回答1: GNU sed sed -r '/title.*java/I!d;s/.*:.(.*).}$/\1/' file java cook book.pdf Java book.pdf 回答2: You can try something like this with

how to extract text which matches particular fields in text file using linux commands

旧时模样 提交于 2021-01-27 11:57:36
问题 Hi below is my text file {"Author":"john" "subject":"java" "title":"java cook book.pdf"} {"title":"Php book.pdf" "Author":"Smith" "subject":"PHP"} {"Author":"Smith" "title":"Java book.pdf"} from the above data i want to extract all titles which contains "java" word, i should get the following output java cook book.pdf Java book.pdf Please suggest me Thanks 回答1: GNU sed sed -r '/title.*java/I!d;s/.*:.(.*).}$/\1/' file java cook book.pdf Java book.pdf 回答2: You can try something like this with

How to delete the lines starting from the 1st line till line before encountering the pattern '[ERROR] -17-12-2015' using sed?

▼魔方 西西 提交于 2021-01-27 11:43:29
问题 I need to delete lines from the 1st line till line before encountering the pattern '[ERROR] -17-12-2015' Currently I am trying the below command but unfortunately it does not find the pattern itself: sed '1,/[ERROR] -17-12-2015/d' errLog What is wrong here? Secondly, the above script will also delete the line containing pattern '[ERROR] -17-12-2015' , is it possible to delete only the lines from the first line to the line before encountering this pattern ? The Sample input is: [ERROR] -09-11

Substitute vertical lines in Bash

六月ゝ 毕业季﹏ 提交于 2021-01-27 06:49:40
问题 I'm having a hard time finishing my script since there's this part which doesn't function the way I wanted it to be. I have this line in my script: cat /home/tmp/temp1.txt | awk '{gsub("~",RS);gsub("*",RS);print}' > /home/tmp/temp.txt It works fine, yes. But when I do something like this: cat /home/tmp/temp1.txt | awk '{gsub("|",RS);print}' > /home/tmp/temp.txt It's not working at all. I wanted to change all my vertical bars into new line and yet I can't achieve it. Please help me with this.

Substitute vertical lines in Bash

无人久伴 提交于 2021-01-27 06:47:43
问题 I'm having a hard time finishing my script since there's this part which doesn't function the way I wanted it to be. I have this line in my script: cat /home/tmp/temp1.txt | awk '{gsub("~",RS);gsub("*",RS);print}' > /home/tmp/temp.txt It works fine, yes. But when I do something like this: cat /home/tmp/temp1.txt | awk '{gsub("|",RS);print}' > /home/tmp/temp.txt It's not working at all. I wanted to change all my vertical bars into new line and yet I can't achieve it. Please help me with this.