sed

How can I remove the stop words from sentence using shell script?

浪子不回头ぞ 提交于 2021-01-07 06:57:50
问题 I'm trying to remove stop words from sentences in file? Stop Word which I mean : [I, a, an, as, at, the, by, in, for, of, on, that] I have these sentences in file my_text.txt : One of the primary goals in the design of the Unix system was to create an environment that promoted efficient program Then I want to remove stop word form the sentence above I used this script : array=( I a an as at the by in for of on that ) for i in "${array[@]}" do cat $p | sed -e 's/\<$i\>//g' done < my_text.txt

How to delete all the lines after the last occurence of pattern?

青春壹個敷衍的年華 提交于 2021-01-07 02:39:17
问题 i want to delete all the lines after the last occurence of pattern except the pattern itself file.txt honor apple redmi nokia apple samsung lg htc file.txt what i want honor apple redmi nokia apple what i have tried sed -i '/apple/q' file.txt this deletes all the line after the first occurence of pattern - honor 回答1: Simple, robust 2-pass approach using almost no memory: $ awk 'NR==FNR{if (/apple/) hit=NR; next} {print} FNR==hit{exit}' file file honor apple redmi nokia apple If that doesn't

How to delete all the lines after the last occurence of pattern?

醉酒当歌 提交于 2021-01-07 02:36:00
问题 i want to delete all the lines after the last occurence of pattern except the pattern itself file.txt honor apple redmi nokia apple samsung lg htc file.txt what i want honor apple redmi nokia apple what i have tried sed -i '/apple/q' file.txt this deletes all the line after the first occurence of pattern - honor 回答1: Simple, robust 2-pass approach using almost no memory: $ awk 'NR==FNR{if (/apple/) hit=NR; next} {print} FNR==hit{exit}' file file honor apple redmi nokia apple If that doesn't

Convert Rows to Columns Shell Script

♀尐吖头ヾ 提交于 2021-01-04 05:32:47
问题 I have data in the below format APP_OWNER : hari APP_AREA : Work:Business Area:AUS APP_ID : 124080 I want the data to be converted to below format. APP_OWNER,APP_AREA,APP_ID hari,Work:Business Area:AUS,124080 I can convert one line but how to do it with 3 lines at the same time? My Attempt with one line sed '0,/: /s//\n/' test.txt Regards 回答1: You may try this awk solution: awk -F '[[:blank:]]+:[[:blank:]]+' '{ v1 = (v1 == "" ? "" : v1 ",") $1 v2 = (v2 == "" ? "" : v2 ",") $2 } END { print v1

Count number of line in txt file when new line is inside data

时光怂恿深爱的人放手 提交于 2021-01-02 18:08:25
问题 I have one txt file which has below data Name mobile url message text test11 1234567890 www.google.com "Data Test New Date:27/02/2020 Items: 1 Total: 3 Regards ABC DATa Ph:091 : 123456789" test12 1234567891 www.google.com "Data Test New one Date:17/02/2020 Items: 26 Total: 5 Regards user test Ph:091 : 433333333" Now you can see my last column data has new line character. so when I use below command awk 'END{print NR}' file.txt it is giving my length is 15 but actually line length is 3 .

Count number of line in txt file when new line is inside data

[亡魂溺海] 提交于 2021-01-02 18:05:29
问题 I have one txt file which has below data Name mobile url message text test11 1234567890 www.google.com "Data Test New Date:27/02/2020 Items: 1 Total: 3 Regards ABC DATa Ph:091 : 123456789" test12 1234567891 www.google.com "Data Test New one Date:17/02/2020 Items: 26 Total: 5 Regards user test Ph:091 : 433333333" Now you can see my last column data has new line character. so when I use below command awk 'END{print NR}' file.txt it is giving my length is 15 but actually line length is 3 .

Count number of line in txt file when new line is inside data

烈酒焚心 提交于 2021-01-02 18:03:45
问题 I have one txt file which has below data Name mobile url message text test11 1234567890 www.google.com "Data Test New Date:27/02/2020 Items: 1 Total: 3 Regards ABC DATa Ph:091 : 123456789" test12 1234567891 www.google.com "Data Test New one Date:17/02/2020 Items: 26 Total: 5 Regards user test Ph:091 : 433333333" Now you can see my last column data has new line character. so when I use below command awk 'END{print NR}' file.txt it is giving my length is 15 but actually line length is 3 .

Count number of line in txt file when new line is inside data

不打扰是莪最后的温柔 提交于 2021-01-02 18:03:15
问题 I have one txt file which has below data Name mobile url message text test11 1234567890 www.google.com "Data Test New Date:27/02/2020 Items: 1 Total: 3 Regards ABC DATa Ph:091 : 123456789" test12 1234567891 www.google.com "Data Test New one Date:17/02/2020 Items: 26 Total: 5 Regards user test Ph:091 : 433333333" Now you can see my last column data has new line character. so when I use below command awk 'END{print NR}' file.txt it is giving my length is 15 but actually line length is 3 .

How to delete all lines before the first and after the last occurrence of a string?

纵然是瞬间 提交于 2021-01-02 06:00:26
问题 cat grab.txt My Dashboard Fnfjfjf. random test 00:50 1:01:56 My Notes No data found. Change Language + English Submit Estimation of Working Capital Lecture 1 Estimation of Working Capital Lecture 2 Estimation of Working Capital Lecture 3 Money Market Lecture 254 Money Market Lecture 255 Money Market Lecture 256 International Trade Lecture 257 International Trade Lecture 258 International Trade Lecture 259 Terms And Conditions 84749473837373 Random text fifjfofifofjfkfkf I need to filter this

SED to remove a Line with REGEX Pattern

时光总嘲笑我的痴心妄想 提交于 2020-12-30 06:59:47
问题 i've got a hundreds of files with thousands of lines, which i need to delete some lines that follows a pattern,so i went to SED with regex .The struct of files is something like this A,12121212121212,foo,bar,lorem C,32JL,JL C,32JL,JL C,32JL,JL C,32JL,JL A,21212121212121,foo,bar,lorem C,32JL,JL C,32JL,JL C,32JL,JL A,9999,88888,77777 I need to delete All the lines that starts with " A " and ends with " lorem " Expected output- C,32JL,JL C,32JL,JL C,32JL,JL C,32JL,JL C,32JL,JL C,32JL,JL C,32JL