sed

SED to remove a Line with REGEX Pattern

和自甴很熟 提交于 2020-12-30 06:59:09
问题 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

How can I combine odd and even numbered lines?

戏子无情 提交于 2020-12-29 10:07:12
问题 I want to combine every even-numbered line with the line above it. Something like: Line one,csv,csv,csv Line two,csv,csv Line three,csv,csv,csv,csv Line four,csv The result should look like this: Line one,csv,csv,csv,Line two,csv,csv Line three,csv,csv,csv,csv,Line four,csv Any ideas how to achieve that in either Perl or sed/awk? 回答1: Perl's builtin variable $. will tell you the line number. $. % 2 will be 1 if $. is odd, and 0 otherwise. Here is a self-contained example; #!/usr/bin/perl use

How can I combine odd and even numbered lines?

本秂侑毒 提交于 2020-12-29 10:05:42
问题 I want to combine every even-numbered line with the line above it. Something like: Line one,csv,csv,csv Line two,csv,csv Line three,csv,csv,csv,csv Line four,csv The result should look like this: Line one,csv,csv,csv,Line two,csv,csv Line three,csv,csv,csv,csv,Line four,csv Any ideas how to achieve that in either Perl or sed/awk? 回答1: Perl's builtin variable $. will tell you the line number. $. % 2 will be 1 if $. is odd, and 0 otherwise. Here is a self-contained example; #!/usr/bin/perl use

How can I combine odd and even numbered lines?

流过昼夜 提交于 2020-12-29 10:04:28
问题 I want to combine every even-numbered line with the line above it. Something like: Line one,csv,csv,csv Line two,csv,csv Line three,csv,csv,csv,csv Line four,csv The result should look like this: Line one,csv,csv,csv,Line two,csv,csv Line three,csv,csv,csv,csv,Line four,csv Any ideas how to achieve that in either Perl or sed/awk? 回答1: Perl's builtin variable $. will tell you the line number. $. % 2 will be 1 if $. is odd, and 0 otherwise. Here is a self-contained example; #!/usr/bin/perl use

Finding lines which are greater than 120 characters length using sed

六眼飞鱼酱① 提交于 2020-12-29 10:03:36
问题 I want to get a list of lines in a batch file which are greater than 120 characters length. For this I thought of using sed. I tried but I was not successful. How can i achieve this ? Is there any other way to get a list other than using sed ?? Thanks.. 回答1: Another way to do this using awk: cat file | awk 'length($0) > 120' 回答2: You can use grep and its repetition quantifier: grep '.\{120\}' script.sh 回答3: Using sed, you have some alternatives: sed -e '/.\{120\}/!d' sed -e '/^.\{,119\}$/d'

How to add a # before any line containing a matching pattern in BASH?

爱⌒轻易说出口 提交于 2020-12-28 09:56:26
问题 I need to add a # before any line containing the pattern "000", e.g., consider this sample file: This is a 000 line. This is 000 yet ano000ther line. This is still yet another line. If I run the command, it should add # to the front of any files where "000" was found. The result would be this: #This is a 000 line. #This is 000 yet ano000ther line. This is still yet another line. The best I can do is a while loop, like this, which seems too complicated: while read -r line do if [[ $line ==

Create symbolic link from find

大兔子大兔子 提交于 2020-12-28 07:51:35
问题 I'm trying to create a symbolic link (soft link) from the results of a find command. I'm using sed to remove the ./ that precedes the file name. I'm doing this so I can paste the file name to the end of the path where the link will be saved. I'm working on this with Ubuntu Server 8.04. I learned from this post, which is kind of the solution to my problem but not quite- How do I selectively create symbolic links to specific files in another directory in LINUX? The resulting file name didn't

process data from text file and convert into csv

我的梦境 提交于 2020-12-27 06:34:27
问题 In our organization, every month a few jobs will run and collect data on server level and it will find what is running on the server and also perform some checks. These files are text files and copied to one repository server. The file name will be <servername>_20200911.log This sample file checks for servers where postgreSQL is running. Date Collected || 11-10-2020 03:20:42 GMT || Server Name || pglinux1 || Operating system || RHEL || passed OS Version || 6.9 || passed Kernel version || 2.6

sed replace xml tag

独自空忆成欢 提交于 2020-12-26 23:26:48
问题 I want to replace value inside a tag in an xml file using sed. <version> xxxx-SS </version> I want to replace xxxx-SS with some shell variable $ver . The final result should be <version>$ver</version> The sed command should also quit after replacing the first instance. So far I have been able to only append to the xxxx-SS and not been able to quit after the first match. sed 's#\(<version>\)*\(</version>\)#\1'$ver'\2#g' test.xml This only appends the value between -SNAPSHOT tag.Basically makes

sed replace xml tag

亡梦爱人 提交于 2020-12-26 23:00:15
问题 I want to replace value inside a tag in an xml file using sed. <version> xxxx-SS </version> I want to replace xxxx-SS with some shell variable $ver . The final result should be <version>$ver</version> The sed command should also quit after replacing the first instance. So far I have been able to only append to the xxxx-SS and not been able to quit after the first match. sed 's#\(<version>\)*\(</version>\)#\1'$ver'\2#g' test.xml This only appends the value between -SNAPSHOT tag.Basically makes