sed

Awk asking combine two files

纵饮孤独 提交于 2021-02-16 20:17:37
问题 I have combined two different files with Same Key by AWK command. And In case there is no key match compare to File1 and File2 then just put "\t\t\t" instead. I have below AWK command. awk -F"\t" ' {key = $1} NR == 1 {header = key} !(key in result) {result[key] = $0 ; next} { for (i=2; i <= NF; i++) result[key] = result[key] FS $i } END { print result[header],"\tValue2","\tValue3","\tValue4" delete result[header] PROCINFO["sorted_in"] = "@ind_str_asc" # if using GNU awk for (key in result)

Split file by vector of line numbers

爱⌒轻易说出口 提交于 2021-02-16 20:10:35
问题 I have a large file, about 10GB. I have a vector of line numbers which I would like to use to split the file. Ideally I would like to accomplish this using command-line utilities. As a regex: File: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Vector of line numbers: 2 5 Desired output: File 1: 1 2 3 File 2: 4 5 6 7 8 9 10 11 12 File 3: 13 14 15 16 17 18 回答1: This might work for you: csplit -z file 2 5 or if you want regexp: csplit -z file /2/ /5/ With the default values, the output files will

sed remove all capital letters

混江龙づ霸主 提交于 2021-02-16 13:54:12
问题 I am trying to delete all occurences of Capital Letters only in the following string with the sed command below but it is only outputting the sting that I enter - how do I put the substitution in correctly ? echo "Dog boy Did Good" | sed 's/\([A-Z]\+\)/\1/g' 回答1: echo "Dog boy Did Good" | sed 's/[A-Z]//g' 回答2: echo "Dog boy Did Good" | sed 's/[A-Z]//g' og boy id ood You substitute something (UPPERCASE) with nothing, and you don't need to group it, because you don't use it later, and you don't

Sed Insert Multiple Lines

ぐ巨炮叔叔 提交于 2021-02-16 10:23:15
问题 I'm trying to do an insert with sed (having just read up on it) and i'm being stumped by trying to insert multiple lines? What i'm currently doing is: sed -i "${line} i\ /* Name - ID */ \ select @ID = NULL \ from Animals \ where VrsnID = @VrsnID \ and Request= \"Request\" \ \ " animalNames.txt Note echo $line == 131 New Problem Everything appears on one line in the output? (also missing the first indent) /* Name - ID */ select @ID = NULL from Animals where VrsnID = @VrsnID and Request=

Sed Insert Multiple Lines

自闭症网瘾萝莉.ら 提交于 2021-02-16 10:22:32
问题 I'm trying to do an insert with sed (having just read up on it) and i'm being stumped by trying to insert multiple lines? What i'm currently doing is: sed -i "${line} i\ /* Name - ID */ \ select @ID = NULL \ from Animals \ where VrsnID = @VrsnID \ and Request= \"Request\" \ \ " animalNames.txt Note echo $line == 131 New Problem Everything appears on one line in the output? (also missing the first indent) /* Name - ID */ select @ID = NULL from Animals where VrsnID = @VrsnID and Request=

bash removing part of a file name

和自甴很熟 提交于 2021-02-15 11:01:24
问题 I have the following files in the following format: $ ls CombinedReports_LLL-*'('*.csv CombinedReports_LLL-20140211144020(Untitled_1).csv CombinedReports_LLL-20140211144020(Untitled_11).csv CombinedReports_LLL-20140211144020(Untitled_110).csv CombinedReports_LLL-20140211144020(Untitled_111).csv CombinedReports_LLL-20140211144020(Untitled_12).csv CombinedReports_LLL-20140211144020(Untitled_13).csv CombinedReports_LLL-20140211144020(Untitled_14).csv CombinedReports_LLL-20140211144020(Untitled

bash removing part of a file name

眉间皱痕 提交于 2021-02-15 11:01:11
问题 I have the following files in the following format: $ ls CombinedReports_LLL-*'('*.csv CombinedReports_LLL-20140211144020(Untitled_1).csv CombinedReports_LLL-20140211144020(Untitled_11).csv CombinedReports_LLL-20140211144020(Untitled_110).csv CombinedReports_LLL-20140211144020(Untitled_111).csv CombinedReports_LLL-20140211144020(Untitled_12).csv CombinedReports_LLL-20140211144020(Untitled_13).csv CombinedReports_LLL-20140211144020(Untitled_14).csv CombinedReports_LLL-20140211144020(Untitled

How to delete rows from a csv file based on a list values from another file?

佐手、 提交于 2021-02-13 12:16:43
问题 I have two files: candidates.csv : id,value 1,123 4,1 2,5 50,5 blacklist.csv : 1 2 5 3 10 I'd like to remove all rows from candidates.csv in which the first column ( id ) has a value contained in blacklist.csv . id is always numeric. In this case I'd like my output to look like this: id,value 4,1 50,5 So far, my script for identifying the duplicate lines looks like this: cat candidates.csv | cut -d \, -f 1 | grep -f blacklist.csv -w This gives me the output 1 2 Now I somehow need to pipe this

How to delete rows from a csv file based on a list values from another file?

百般思念 提交于 2021-02-13 12:15:52
问题 I have two files: candidates.csv : id,value 1,123 4,1 2,5 50,5 blacklist.csv : 1 2 5 3 10 I'd like to remove all rows from candidates.csv in which the first column ( id ) has a value contained in blacklist.csv . id is always numeric. In this case I'd like my output to look like this: id,value 4,1 50,5 So far, my script for identifying the duplicate lines looks like this: cat candidates.csv | cut -d \, -f 1 | grep -f blacklist.csv -w This gives me the output 1 2 Now I somehow need to pipe this

How to extract characters between the delimiters using sed?

回眸只為那壹抹淺笑 提交于 2021-02-12 11:41:22
问题 I have just started learning sed. I want to extract and print the characters between the > and < delimiters. Here the text in my data file: <span id="ctl00_ContentPlaceHolder1_lblRollNo">12029</span> <br /><b>Engineering & IT/Computer Science</b><br /> <div id="ctl00_ContentPlaceHolder1_divEngITMerit"> <span id="ctl00_ContentPlaceHolder1_lblEngITSelListNo">3rd Provisional Selection List</span> <tr><td style='width: 200px' class='TblTRData'>IT/Computer Science/Software</td><td style='width: