Manipulation of text by programs, scripts, etc.
2
votes
3answers
82 views
Process `find` output parse out certain fields
I have find output as follows:
/var/data/run/stores/user.rstd/info.settings:4: Password = "xxxxxxx";
In this example, "user" and the value of "Password" ("xxxxxxx";) need to be redirected to a new ...
0
votes
1answer
17 views
Remove all directories in output of find and redirect output to new file
If my find output looks like this:
/var/log/data/run/account1.ext
How can I trim off everything except the "account1" and redirect into a file?
Note: this is just an example the actual folders ...
-2
votes
2answers
28 views
text file sorting
I have a log file like
name = CE_20_122 assigned_hostnames = host1 cpuset_name = usr_1397032
name = CE_21_122 assigned_hostnames = host4 cpuset_name = usr_1397028
name = CE_22_122 ...
7
votes
5answers
371 views
How to replace epoch timestamps in a file with other formats?
I'm looking for some help with a file I have. It contains epoch dates which I need converting to human-readable. I already know how to do the date conversion, eg:
[server01 ~]$ date -d@1472200700
Fri ...
-3
votes
1answer
41 views
Blockwise text replacement [on hold]
I checked sed & perl commands, but could not determine how to replace a text block with another one.
For example a matching text block
foo bar
boo far
Should be replaced with
this is
my new
...
3
votes
2answers
105 views
sed multiline recursive pattern substitution
From the following input:
serial0/0
SSL disabled
eth0/0
SSL enabled
SSL only
eth0/1
SSL disabled
bgroup0
SSL enabled
eth0/2
SSL disabled
eth0/3
SSL disabled
eth0/4
SSL disabled
bgroup1
SSL disabled
...
-1
votes
2answers
29 views
Sed or AWK: Add line after each ocurrance of pattern between a range of line numbers
I need to add a line of text after each occurence of a pattern. I need this:
pattern1
pattern2
To look like this
pattern1
pattern2
new line data here
The new line data will always come after ...
5
votes
2answers
113 views
how to select n first characters from first column according to the number of the second column
During my workflow I have created this file:
AAGGAGGGAGCTGCATGGAACCTGTGGATATATACACACAAGGTTAACCTCTGTCCTGTAAA 8
GGAGTTCAGATGTGTGCTCTTCCGATCTGGAGGTCTCTGCTGGGGCCACCCTGTCCTCTCAG 30
...
1
vote
2answers
28 views
Capture output of curl after a string to a file
I would like to output everything after the string "director-services" to a file from a bash script.
$ curl localhost:9201/_cat/health
1472487809 12:23:29 director-services green 3 3 828 276 0 0 0 ...
1
vote
1answer
21 views
comparing two columns
I want to print OK if in column3 all fields are OK from below output.
port mcg clk stat
------ ------- ----
OK EXTCLK1 OK
OK CLK3B OK
OK CLK3A OK
I have tried ...
4
votes
3answers
642 views
How to replace “^” with space?
How can ^ be replaced with space in Unix?
Input:
ab^cd^ef
Output:
ab cd ef
I have tried sub(/^/, " & ", str) but output is same as input.
0
votes
0answers
37 views
Divide numbers in field based of another field value [on hold]
I'm looking to divide PERCENT="" fields by a number (in this example 5). There are other PERCENT="" fields in the data which should not be modified. The ones I want divided by 5 have START_LV="" and ...
-1
votes
1answer
24 views
Divide numbers in specific field
I am looking to divide numbers inside the PERCENT="" field in my data that is followed by both START_LV="" and END_LV="". I want to divide the numbers by 5 however the numbers must be whole. Also if ...
-1
votes
2answers
27 views
AWK Grouping Based On Line Containing Specific Character
The source looks like this:
test/snmp/result/08-28-2016_12-30/AAAAA/hostname01_192.168.1.1
161/udp open snmp
| snmp-brute:
| comstring1 - Valid credentials
|_ comstring2 - Valid credentials
test/...
2
votes
1answer
40 views
Appending a variable to different lines of a file in bash [duplicate]
So say I've got a file with the following text in it.
And the source file I'm reading is like this:
#0 abc 2016-08-06 01:12:57 AM 9.1% 779.9M of 1G 156.3M of 1G
#1 abc 2016-08-06 02:33:47 ...
0
votes
1answer
33 views
Bash script to filter specifc entries from snmpd.conf
I am working on a script to filter community entries from snmpd.conf
Script is:
SERVER=$(hostname)
touch /tmp/snmp_audit_$SERVER
echo $SERVER >> /tmp/snmp_audit_$SERVER
SNMP=$(cat /etc/snmp/...
3
votes
1answer
35 views
Search and remove special character
I have below string in my DDL file and i want to remove the last ) character.
DDL has the ) character in many places, but I want to remove only in below place indicated.
..
`event_sts` string,
`...
0
votes
1answer
33 views
Search a file for a number that is between two specific numbers
$ cat logfile
1;1472223253;frank;12344;1472224386
2;1472223265;andrew;shop;
3;1472225515;frank;12345;1472225531
4;1472225526;joe;12344;1472225534
What can I run to get lines that contain numbers ...
0
votes
0answers
47 views
Parsing ansible output in shell script using sed/grep
I have a shell script which executes an ansible playbook and I want to process the output of this playbook. I am not sure how can I do this.
Script:
#!/bin/sh
ansible-playbook -i inventory/ec2.py ...
6
votes
7answers
497 views
How to wrap two line into single line with delimiter
I have executed below command
cat /proc/loadavg && date
Actual Result:
0.00 0.00 0.00 1/803 26256
Fri Aug 26 09:00:56 EEST 2016
Expected Result:
0.00 0.00 0.00 1/803 26256 @@ Fri Aug 26 ...
1
vote
2answers
47 views
Shell script to only count consecutive days
I was wondering how I would go around to do this.
This is an example of my output
Sun Aug 21 2016 03:00:00, BLAH
Mon Aug 22 2016 03:54:00, BLAH
Tue Aug 23 2016 04:22:11, BLAH
Thu Aug 25 2016 05:00:...
1
vote
1answer
17 views
Rename command to delete substring
I am trying to batch rename the following files:
art-faculty-3_29060055362_o.jpeg
fine-arts-division-faculty-2016-2017-5_29165851925_o.jpeg
theatre-faculty-2016-2017-1_29132529356_o.jpeg
art-...
0
votes
2answers
55 views
Unix/Linux - Replace words between parentheses
I want to replace words between parentheses in unix/Linux- as an example below. I am trying to automate this so that it makes my work easy with just one code included.
I have the below string in my ...
0
votes
1answer
56 views
Grep from one line and print specfic text above that line
I am currently facing a challenging script where I need to grep for the following 700e10 for example under the column partnum and find/grep for "rstcb" above that line. The problem is that it is not a ...
3
votes
1answer
34 views
Awk - Match Values Between Two Files and Create a New File
I have two files that I am trying to compare, and create a final.txt file with data that exists from both of those files.
File1 - column 1 and File2 - columns 2 contain the value that I need to ...
6
votes
1answer
153 views
Print columns that start with a specific string
I have a file that looks something like this:
ID101 G T freq=.5 nonetype ANC=.1 addinfor
ID102 A T freq=.3 ANC=.01 addinfor
ID102 A T freq=.01 ...
0
votes
1answer
35 views
Remove last character from string captured with awk [duplicate]
I need to remove the last character from a string in this command:
sudo docker stats --no-stream 39858jf8 | awk '{if (NR!=1) {print $2}}'
The result is 5.20% , I need remove the % at the end, giving ...
1
vote
1answer
35 views
Insert a line before a certain line in a file
I found how to insert a line after a certain line in bash
sed -i '/oh-my-zsh.sh/aplugins=(git symfony2)' ~/.zshrc
Result:
source $ZSH/oh-my-zsh.sh
plugins=(git symfony2)
But I would like to ...
-4
votes
0answers
34 views
How to grep for specific string in a file [migrated]
this is my input file
<MessageOut>
<Attribute name="Session-Id" value="22250"/><Attribute name="CC-Request-Type" value="2"/><Attribute name="CC-Request-Number" value="1"/><...
5
votes
2answers
435 views
arithmetic operations between files
Say I have these two input files:
> file1
2
3
4
> file2
10
100
1000
And I would like to compute: file1/file2 for each line, resulting in file3:
> file 3
0.2
0.03
0.004
Divisions in ...
1
vote
1answer
26 views
Ssh into multiple servers and merge files into one
I was able to do it with one server with the following code:
ssh server001 << EOF
cat /dir/file001.txt >> somefile
EOF
With multiple servers, my script is able to ssh into the servers ...
1
vote
3answers
45 views
Extracting data from a variable at the command-line
I have two variables $dc_list and $TEST_VENUE . If I do echo in bash
echo $dc_list
{"active-production-dc":"sc-va1","standby-production-dc":"sc-tx2","active-integration-dc":"int-va1","standby-...
2
votes
2answers
33 views
awk scripting to scan files for certain words and create output
I have many lines like:
uid: jdoes mail: [email protected]
mail: [email protected] uid: mdoes
uid: kdoes mail: [email protected]
mail: [email protected] uid: tdoes
How do I rearrange them to look like :...
3
votes
2answers
33 views
transpose/pivot csv text file
I need to transpose/pivot a CSV file. Don't know if that is possible
Suppose this CSV file content:
filename;rating;id;summary
S4348gjO.doc;good;0001;describing how to reach your goals
S4348gjO.doc;...
0
votes
2answers
49 views
How can I print the nth line of a file, and detect whether the process failed?
I have a file called namelist with names like this:
george
cindy
chester
I'm using nl namelist to produce:
1 george
2 cindy
3 chester
I want to use that name list in a script that contains ...
0
votes
1answer
58 views
Calculate average values for each day over multiple years
I have some "CSV" data (actually using ; as a delimiter)
having a row for every day from 1971-01-01 through 2099-12-31
(a span of 2099−1971=128 years). The data are organized as follows:
YEAR;MONTH;...
1
vote
2answers
22 views
replace pattern inside a line from pattern at the beginning
Trying to replace a pattern inside text lines with a pattern found at the very beginning of the same line.
Having some text:
number4456 reports a high level of error
number3458 taking a proper error ...
1
vote
0answers
36 views
How to match two or more cloumns values from different tables present in a single csv file?
xyz.csv file
physical_hosts,physical_host_id,virtual_host_id,physical_host_name,private_ip,administrative_status,operational_status,,,,,,,,,,,,,
start_physical_hosts,,,,,,,,,,,,,,,,,,,
,o1,1,sangram,...
13
votes
10answers
794 views
Remove newline character just every N lines
Processing text, I need to remove the newline character every two lines.
Sample text:
this is line one
and this is line two
the third and the
fourth must be pasted too
Desired output:
this is ...
0
votes
2answers
38 views
Add value in a field for a given condition in specific column of file
I need prefix digit 9 to the second column of file when the value of second column begins with 10 and length of second column is 8
Example
file.txt
T01|10017516|01|ABCD|1203|EFGH
T01|10905704|01|...
1
vote
1answer
58 views
keeping line number when processing text inside a grep
Got a tricky and complex program that is used for pre-processing text in order to send it to a Machine Learning software.
To make long story short:
The bash script gets inside a folder where ...
3
votes
1answer
40 views
Cat prepend to first line, NOT new line
So I have kinda just resigned to using nano for this, but I though I would put it out on Unix.Linux to A) Challenge somebody and B) learn how/if It can be done.
I want to prepend a link to an rsa ...
2
votes
2answers
61 views
Read text file and store the info into variable
I have a text file in which the records are in any one of the formats below:
SCI.txt
12-12-1990
12-12-1991
CSE Department
Or
12-12-1990,12-12-1991,CSE Department
I want them to be stored in 3 ...
0
votes
4answers
60 views
extract line number and pattern in file at the same time
I've read a bunch of text files to extract some patterns. I need the line number too but the line number must be removed before the final grep (but can be saved for further processing maybe using ...
1
vote
3answers
26 views
Extract everything before the matching string
I have a string
hdfs://ussbssn01.us.xyz.com//data/ip/list/usa/
and what I want is just
hdfs://ussbssn01.us.xyz.com//
i have tried awk, sed but I did not get what I was expecting because the ...
0
votes
2answers
34 views
How can I add text to the end of a line that contains multiple strings?
I have a file like this:
1;1471375551;joe;WO12344;
2;1471378551;frank;WO12345;1471380211
3;1471383211;frank;WO12345;1471385211
4;1471385311;frank;WO12345;
5;1471385311;joe;WO12346;1471388211
I'd ...
3
votes
3answers
48 views
How to double each line and change digits within each line differently in linux?
Input file looks like:
1 0 0 000 3444
2 3 3 456 6875
3 0 0 023 3300
4 2 2 211 1000
first: I want to have 2 copies of each line:
1 0 0 000 3444
1 0 0 000 3444
2 3 3 456 6875
2 3 3 456 6875
3 0 0 ...
1
vote
1answer
36 views
How to parse a data file to extract specific data and format for other use?
Given a data file which contains various content, I would like to first ignore any line that does not start with an IP address, then output the IP address followed by any string found in the braces ...
0
votes
3answers
44 views
Replace Similar Worded Line through SED
I have a file sample_init.ora
There are 2 lines in the file.
db_create_file_dest="DATAG"
control_files=('DATAG/DBNAME/controlfile/control01.ctl','DATAG/DBNAME/controlfile/control02.ctl')
Now, I ...
2
votes
3answers
206 views
awk multiple pattern match and print in single line
I have the following file:
$ cat disk.out
disk0
fcs0
text
text
text
disk1
fcs1
text
text
text
text
...
What I am trying to achieve is match "disk" + "fcs" and then print the pair in one line, like ...