Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

-5
votes
3answers
103 views

How to add all the numbers of a specific column in UNIX without using awk command?

Let us take a sample file with the contents below, an expense report containing items and their prices: $ cat file Item1,200 Item2,500 Item345,900 Item20896,800 Item111,600 Now, a friend challenged ...
2
votes
2answers
126 views

Multiplying numbers in-place in a file

I have ASCII file contain numbers as follow: 1 2 3 5 6 9 7 8 9 . . . . . . . . . . . . . . . etc I want to upgrade this file by multiplying each value by "3" to get : 3 6 9 15 18 27 21 24 27 ...
2
votes
1answer
34 views

Tweak perl script for human-readable dmesg output

In RHEL 6 I have the kernel parameter: printk.time=1 So that my dmesg would have a timestamp. However it shows in seconds from restart, like this: [12.23456] I found a script that you place ...
-2
votes
2answers
62 views

Find all line in a file which start with g or any digit from 0to9

How do I find all lines in a file which start with g or any digit from 0 to 9? Can any one help me using command line? I try and I know how to do if start with g but don't know how to do with g and 0 ...
1
vote
2answers
72 views

how to edit next line after matching pattern and append the line if doesn't exist

I am looking for changing a file content which is repeated twice with that replacement I want to add extra line to second content in the same file Example file User YOURNAME IdentityFile ~/.ssh/...
2
votes
3answers
54 views

How to delete a variable string in file

Actually I am using sed -e s/Perro-A//g -i *-a.log to delete the string Perro-A from many files ending with *-a.log. But sometimes in the files I might not have Perro-A; I might have strings ...
1
vote
3answers
96 views

How to print one column to other columns combined path without awk?

I want to realize the same function as the awk command: awk -F ";" '{print $3 > "/" $1 "/" $2}' file For example: I have a file with two lines as input: path1;filename_1;f3_1 path2;...
0
votes
3answers
69 views

Awk command to get the next line from the matched pattern and crop the string in between two patterns

I need to get the next line after matched pattern and need cut or crop the value in between two patterns from that line. Sample Source file <h2>Commodity Information</h2> <dl> ...
0
votes
2answers
35 views

Extract the second quoted string in a line of output

I have a line of output with three quotes, and I specifically need to extract the second quote into a variable. So for example, with the command cmd | grep tokens, I get the following output: Output ...
1
vote
4answers
764 views

With the Linux “cat” command, how do I show only certain lines by number

If I use cat -n text.txt to automatically number the lines, how do I then use the command to show only certain numbered lines.
1
vote
1answer
54 views

uniquely remove unwanted lines in multiple files

I need to remove unnecessary data from multiple output files part of each file looks like this # BLASTN 2.3.0+ # Query: M03117:99:000000000-ALL7G:1:1101:18697:4431_2:N:0:196 # Database: /home/alex/...
0
votes
3answers
30 views

Extract a part of one line and sort

I have output similar to the following: [test output] my name is bob this is a random string [test output] my name is jim this is a randong string2 [test output] my name is bob this is a randong ...
1
vote
2answers
69 views

Rename all spaces in image file names inside html php files

Inside different htm.gz, html.gz and php.gz web files I have images and the ones in .jpg format have name with space instead of "-", but in /images/ directory where all images are located they have "-"...
1
vote
2answers
55 views

How to check if some recurring text is missing in a text file?

I have a text file that looks like this: { "mimeType": "web", "body": "adsfdf", "data_source_name": "abc", "format": "web", "url": "http://google.com/", "urls": "...
2
votes
2answers
42 views

Command to print content before a symbol (last character in a line)

Let's consider I have 3 files: abc_def_12345.zip abc_123.zip abc_def_ghi_3432.zip I want to print only the characters before the last underscore(_) The expected output is: abc_def abc abc_def_ghi
1
vote
1answer
31 views

sed - pattern only on some predefined lines

I want to use sed to give me some lines from a file. I want to extract these lines only within some part of the file, which I know. E.g. I have a file with 100 lines, and I am seeking for lines ...
0
votes
3answers
41 views

Change CSV records sequentially

I want to replace the text sequentially in a file. The file's contents are: 1,01-JUN-2016,ABC 2,01-JUN-2016,ABC 3,01-JUN-2016,ABC 4,01-JUN-2016,ABC 5,01-JUN-2016,ABC 6,02-JUN-2016,ABC 7,02-JUN-2016,...
2
votes
6answers
118 views

Comparing 3 lines and 2 lines in BASH

I have a text file which looks like this. 2014-11-24 12:59:42.169 101.0.0.0 source 2014-11-24 12:59:40.375 104.156.80.0 destination 2014-11-24 12:59:36.729 104.219.48.0 destination 2014-11-24 12:59:...
2
votes
3answers
234 views

Append data of multiple files to new file separated by a line

I have more than a hundred firewall rules for many different customers in discrete files in a folder. Suppose the filenames are: 1.wawa.com_firewall_rule 2.newa.com_firewall_rule Each file ...
1
vote
2answers
62 views

Merging Two Files Columns

I want to add 6 field of File2 in last field of File1, i'm using following command but unable to get output. awk 'FNR==NR{a[$1]=$6; next} {print $0,a[$1]}' File2 File1 File1: zehriscollection.co....
6
votes
3answers
666 views

merge two files, first line from first file followed by first line from second file [duplicate]

I have two files : f1: f2: ============== =============== some text line 1 A1 some text line 2 ...
2
votes
1answer
169 views

How to filter lines passed through a pipe?

I've got a command foo that outputs a list of filenames: $ foo file1.a file2.b file3.a And a command bar that accepts the names of .a files as arguments and does some processing: $ bar file1.a ...
3
votes
1answer
51 views

List names of files containing a string that occurs between two other strings

I need to print a list of files with match a specific pattern -- a string occurring between two other strings. How do I do that. I don't want to extract text, just list the files that match this ...
2
votes
1answer
50 views

How to choose the highest number element in many files with many arrays

I have many files which each one contain many arrays(like input 1 and 2, below). Each array has two element numbers in the second row. I need to use a logical criterion to choose the highest number ...
3
votes
1answer
60 views

awk or sed command to start each column of file from desired locations or Byte Position

I have a source file format like below containing 15 columns and so many rows: 23.5 31.5 5.00 255 0 255 2 1 sal unknown sa time sps meter ms 25.5 32.5 6.00 0 255 0 2 2 sal unknown sa time sps ...
-1
votes
1answer
54 views

Extract Information From Logs

Unable to grep third field "Email From": While I'm using this command to grep first two fields: echo "TimeStamp Email To: Email From:" && awk '{print $1,$6}' logs Logs: 2016-05-23 11:01:...
-1
votes
1answer
39 views

Extract string from first character till string pattern

I have a implicit file with **$&*#@** as field delimiter and **$#@&*** as record delimiter. Below is an example, 100$&*#@200$&*#@50$&*#@Some String$&*#@2016-01-01 101010$#@&...
1
vote
1answer
40 views

Replace only the first character of a matched pattern

I need to write a sed command that reads from a file and replaces the first character in each line with 0, only in the event that the first and second character in that line is a digit (and leave the ...
2
votes
2answers
48 views

How to check if input contains all 26 chars

I got a input file which contains one char per line I want to check if the file has exactly all 26 letters. I found that uniq -d can help to get the repeated one. But how to find out the missing ...
2
votes
1answer
21 views

Strings from two distinct arrays not matching?

I'm trying to filter one array from another array. That is, I'm trying to create a third array with a logical not-intersection. The best I can tell, it appears this block of code never matches, and ...
1
vote
0answers
22 views

Compare Two File And Match Column One [duplicate]

Compare two files if second file contains a domain which is not found in first file than add "Static" in second field. File1: cleanwatersaveslives.com WordPress blood-mate.com ...
2
votes
3answers
131 views

Extract a line if the first field contains a dot

The actual data is: Dolibarr techpubl http://techpublications.org/erp tekstilworks.com WordPress tekstilw wbq.dandydesigns.co WordPress ...
0
votes
1answer
44 views

How to multiply numbers located in two different files

I have two files ... First file(input 1): 1: 6.1703 44 14.7262 46 18.3255 2: 6.1932 44 52.9379 46 4.30653 3: 6.5664 45 2.82839 46 3.1275 4: 8.0923 44 14.1076 Second file(input 2): 43 ...
1
vote
2answers
21 views

How do I swap two fields separated by backslash and output them separated by an at sign?

Original file contains email addresses in the following format: domain.com\first.lastname I have used sed to replace the backslash with an @ sign. I've tried various suggestions to swap the domain....
0
votes
0answers
31 views

add a column with data to a file based on the same name in another column [duplicate]

I would like to add an additional column(s) with some info to a file based on the same names in the first column: First file: OTUId 1 2 3 OTU_93 -2413 -2209 -878 OTU_19 -1426 -1388 -...
2
votes
2answers
118 views

How to multiply the array elements by itself

I have an array file and I need to do a math operation with the elements. The operation that I need to do is to multiply the element by itself, the to print it. The input looks like this: 1: 6.1703 ...
1
vote
2answers
52 views

Convert command output to csv, with time stamp

I want to test a speed connection with terminal command: ./speedtest-cli And it returns This: Retrieving speedtest.net configuration... Retrieving speedtest.net server list... Testing from Moscow,...
0
votes
3answers
61 views

Regex pattern to replace multiple values via sed

I have a script in which I need to parse the IP address of the localhost, and replace the 2nd octet with a different value, but the value being substituted depends on what the value currently is... ...
3
votes
3answers
52 views

Grep/awk/sed for lines composed of only two letters, and lines that start with a letter and meet a certain length

Not sure how many people are familiar with DNA sequencing data, but if this is part of my file (lines starting with ">" are IDs, and lines starting with a letter are DNA sequences): >NB501013:9:...
1
vote
4answers
64 views

Extract X number of minutes from the current time from a logfile

I have a logfile with the following timestamp format 2016-06-02 13:59:58.069 The log I am working with spans about an hour. 2016-06-02 13:05:06.144 2016-06-02 13:05:06.144 2016-06-02 13:05:06.160 ...
2
votes
2answers
45 views

Print text between two strings - omit second occurrence

I have an instruction file with a lot of steps. I'd want to view a single desired step in a shell, without graphical environment. What I do right now, as pointed out by alemol, is using sed to extract ...
1
vote
1answer
46 views

How to sum specific rows of a matrix

I need to sum the matrix elements of specific rows for each column. An example of the matrix is given below(input). So the matrix has 4 columns and 6 rows of numbers. I need to sum the numbers of ...
1
vote
4answers
103 views

How can I cut the character from “Thu Jun 2 08:11:53 PDT 2016” such that to display only 08 11

How can I cut the character from "Thu Jun 2 08:11:53 PDT 2016" such that to display only "08 11"
0
votes
2answers
63 views

I want to edit the text of a specific file

I would like to modify the configuration file, as shown below. What can I do as a shell script ? before Section "InputClass" Identifier "calibration" MatchProduct "Touch" ...
0
votes
2answers
58 views

Comparing two lines in BASH using awk

I have text file like this. 2015-11-24 12:59:37.112 128.206.6.136 source 2014-11-24 12:59:36.920 8.8.8.8 source 2014-11-24 14:59:38.112 23.234.22.106 destination 2014-11-24 13:59:37.113 23.234.22.106 ...
1
vote
4answers
64 views

How to use Unindented line as the Record Separate in awk cli

I have a log file that look like: 2016-05-31 09:54:36 (16667) heritage_w? From: ip68-8-49-100.sd.sd.cox.net User: user1wizard (wizard) Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/...
1
vote
1answer
80 views

Summarize certain data fields of apache CLF log file

I want to grep some information from raw combined log format apache logs: 51.254.56.62 - - [01/Jun/2016:20:49:28 +0500] "GET /vendors/jquery.slimscroll.min.js HTTP/1.1" 404 - "http://networkconfig....
3
votes
2answers
70 views

Compare lines and upgrade two different files

I have a couple of text files with the following features: $ cat file_1 Line A Line B Line C Line D $ cat file_2 Line A Line added 1 Line B Line D Line added 2 They are such that file_1 has some ...
0
votes
2answers
32 views

Interchange two columns

I am trying to swap the "Hits" and "Domain" column. cat filename Output: Hits Domains 204492 greenlivingasc.in 37102 smcracks.uk 17410 bahriains.org 10975 ...
1
vote
2answers
41 views

How to append some string combined with the pattern at the end of line with the pattern

I want to append .com at the end of line for every line matching the pattern in /etc/hosts file. Sample file content: 127.0.0.1 localhost 1.2.3.4 hostname1 hostname1.xyz hostname1.xyz. 1.2.3....