Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

1
vote
3answers
48 views

How to grep “block” strings out of a weird file

Command on AIX is: [root@hx042:/home/user1]$ lqueryvg -Atp hdiskpower13 0516-1396 lqueryvg: The physical volume hdiskpower13, was not found in the system database. Max LVs: 256 PP Size: ...
3
votes
3answers
43 views

Grep that works with overlapping patterns

I want to count the number of repeating patterns aa in a very big file. So I use the following command: grep -o "aa" ./bwt/dblp.txt | wc -l This works, except when I have a string such as aaa, ...
3
votes
1answer
127 views

Replace with sed until match in a line

I have to replace all "." characters before the "=" character in every line in a file. The lines are like this: one.two.three=something four.five=1 six.seven=127.0.0.1 ...
3
votes
4answers
274 views

how to make list of strings from file where this strings are in own line

I have file: xxx.lst with values: 111 222 333 I just need to make one line with: 111 222 333 into a variable or standard output.
0
votes
2answers
41 views

Select rows based on the values of a specific column (not the first column)

I would like to read a file.csv file and keep the rows (i.e., all the columns) of the file if and only if the sixth column of that file matches values in user_ids_to_keep.csv. The file.csv file I ...
2
votes
3answers
50 views

Print up to (and including) the nth occurence of a pattern in a line

Let's say I have multiple lines similar to below in a file. Turbo is a cat. cats are good. cats are not dog. Coco is a black cat. cats are furry. cats are not dog. now, if want to grep all the ...
3
votes
2answers
129 views

How to extract strings from one file into multiple files

I have a file, xxx.lst with the following data: aaa 111 bbb 222 ccc 333 I need to make 3 files called 111.lst, 222.lst and 333.lst respectively with aaa in 111.lst bbb in 222.lst and ccc in ...
-1
votes
2answers
34 views

awk print all matching lines including duplicates [duplicate]

How can I print all matching lines between two files including the duplicates sourcefile: SNP value RS1 0.55 RS2 0.52 RS3 0.25 RS4 0.22 queryfile: SNP RS1 RS2 RS2 RS3 RS4 RS4 Desired output: ...
0
votes
2answers
54 views

wc -l command issues in SunOs to Linux migration

We are migrating from SunOS to Linux. I'm facing some problem with wc -l command. When I used wc -l <file_name>, SunOS is giving leading spaces before count where as Linux there are no leading ...
0
votes
1answer
43 views

Copy last n-lines from one file to another

In the context of adding the same lines at end of the .bashrc or .vimrc files of several user accounts on the same machine, what would be an easy way to copy the last n-lines from one shell script to ...
-1
votes
3answers
28 views

Write in a part of a document the current time? [closed]

How can you write the current time from terminal in a document? In a specific place of the document, I mean.
0
votes
2answers
36 views

Remove lines in a file where pattern only occurs once

I have a CSV file. It is ordered by an identifier the first field. The identifier in the first field can appear in either 1 or in 2 lines in the field. I want to remove all lines in the file where ...
1
vote
1answer
38 views

Using sed to replace spaces in text files with _ only when between “ ” after specific string

How can I use sed to substitute a space with an _ only when it occurs in a text file after the string title= and between " " For example (lines in a text file): title="This is the title of my book" ...
0
votes
2answers
34 views

How can I remove a last pipe delimiter from a pipe-delimited file in Unix?

How can I remove a last pipe delimiter from a pipe delimited file in Unix? My input lines look like: 1|GAbriel|10 ground floor|naik Badi|trend|account|detail|hints|||||| Expected output is: ...
0
votes
4answers
77 views

Increment value and swap next two lines

I have a text file with a sequence of lines repeating multiple times. For example: param id: 0 value: 2 description: "hello" param id: 1 value: 3 description: "world" I want to move description ...
4
votes
4answers
181 views

Count text occurrences per line

I have to parse huge text files where certain lines are of interest and others are not. Within those of interest I have to count the occurrences of a certain keyword. Assumed the file is called ...
2
votes
2answers
59 views

find and replace double bracket values

I have a requirement to replace the [[KEY]] in double brackets in one of the html file with VALUE. Key values are available in different files. After replacement, I need to put output in separate ...
0
votes
1answer
27 views

print only lines that starts with digit from specific column

I have a file which has second column as hostname of all hosts in my network: Host example.com (x.x.x.x) is up (0.0041s latency). And so on, but many lines doesn't start with hostname in second ...
0
votes
1answer
29 views

Extract two lines following a line with a specific value

I have a text file and I would like to extract the two lines of data following a line containing only "Name" as a value. Name 032 Express intent to engage in diplomatic cooperation (such ...
1
vote
1answer
60 views

Break up large log files

I am trying to break a large log file into smaller files based on date. The file is of the following form, where some lines may not have a date. Those lines should be included with the previous ...
0
votes
2answers
38 views

Remove string with spaces and quotes from xml file

I would like to remove the string currencyId="GBP" from an xml file. Please note there is a single space before the first letter c. I am having trouble parsing the data and removing this string ...
1
vote
1answer
37 views

Bash script to summarize “ last -a ”

I would like to make a shell script such that it runs the " last -a " command and summarizes it's data in the form : userID : number of login sessions Host or ip1 - number of ...
0
votes
1answer
27 views

Most elegant pipe to get rid of empty lines you can think of? [duplicate]

For e. g., less has option --squeeze-blank-lines (or -s in short) and it squeezes multiple blank lines into single blank line, buuut, less wouldn't do this being used as filter (i. e., having its ...
1
vote
4answers
28 views

Change dictionary from finnish-czech to czech finnish

I have this file http://sinivalkoiset.wz.cz/ostatni/finnish-czech.txt and I would like to swap first collumn with the second one. I used the sed commend sed -ne 's/\([^a-z A-Z].*\) \(.*\)$/\2 \1/ p' ...
0
votes
1answer
21 views

How to replace a text with another in Perl

Using tr command I want to convert Hello into Hii. My command was: $_="Hello"; print; tr/Hello/Hi/; print; But the result was Hiiii. What did I do wrong? What is the right way to do it?
2
votes
2answers
79 views

Sorting one file line by line based on another file

I'm trying to sort the rows of a text file based on an 'index' in another file, such that the text file is arranged, row by row, in the same order as the index file. The following code achieves what ...
3
votes
2answers
186 views

How to replace a piece of text only if it doesn't appear elsewhere in the file?

Suppose I have some text like this (output of objdump -d): 0: 0f a2 cpuid 2: a9 01 00 00 00 test eax,0x1 7: 74 01 je a ...
0
votes
1answer
31 views

How to Extract the current date Date Log from catalina.out file

I have 2.5GB catalina.out file. I need to extract the current date's logs from this file. Please help me to achieve this. Please see below my log file format: 2016-02-15 19:49:45 INFO ...
3
votes
1answer
54 views

A common way of combining two files in Solaris and Linux

I am trying to write a script that would combine two files into one and should work in both Solaris 5.10 and a Linux box. File1: dit710 dit710 dit720 dit720 File2: FacA D0000000000000001 FacA ...
0
votes
4answers
48 views

How do I insert the first line of one file into the first line of another?

I've got a head command to get the first line of a file and a sed command to insert before the first line of a file. How do I combine these so I can insert the extracted first line of one file before ...
-1
votes
3answers
33 views

How to filter log file for string inside single quotes?

I have a log file, which outputs information this way: 2016-01-01: foo bar fnord 2016-01-01: this is static 'this is of interest' some blob bar 2016-01-01: this is static 'this is of interest' some ...
1
vote
1answer
27 views

Split large log file into pieces based on date

I am trying to work out a Linux command to split a large log file into pieces based on date. Using ...
0
votes
2answers
31 views

Return part of string in text file

Background: All logs go to csv for mysql import. Have a great many logs with data like: Moon,Srv-1,2016-04-04 06:59:48,Entry #103 (s) test (AlphaNum_Need_This_32_Char_Long1),Msg On (ref2357 : Act) ...
0
votes
1answer
42 views

Column comparison using awk [duplicate]

I would like to compare the first column of file1 with the second column of file2 and only if they match it should display any matching lines in file2 only as the output. The columns are separated by ...
3
votes
2answers
696 views

In vi/vim, how do I append to a file instead of overwriting it?

I know I can write to a file by simply doing :w <file>. I would like to know though how can I write to a file by appending to it instead of overwriting it. Example use case: I want to take some ...
1
vote
2answers
37 views

How to treat remote txt file as stream?

A web service writes its output in a text file. I can fetch that log via: curl -u user:password -k https://log.my-app.com/log.2016-04-04.txt Yet this always only fetches a current "full" file even ...
0
votes
0answers
24 views

Remove lines existing in the first file from the second file and remove duplicate lines from a file [duplicate]

First Question Without having to deal with a perl or php script, can I do this efficiently with some common bash programs? With wich command? can you provide a sample? Second Question Can I take a ...
1
vote
2answers
29 views

Looking for a pattern with conditions

I have a huge file in which I want to look for a word, say pattern. I'm trying to illustrate my case with an example. Suppose I have in my file somewhere Sample-pattern="abc" I want to write a ...
0
votes
1answer
16 views

Separate values based on record

Using awk is it doable to separate values based on a certain record? Let's say we have following file: ACCJSH PREMIUM I5001 7 5976 7 @# 0.2 5195 5231 0.2 @# 39 5197 39 @# If we take the @# for ...
3
votes
3answers
94 views

Is it possible to use grep lookaroud multiple times?

<table name="content_analyzer" another-key="id9"> <type="global" /> </table> <table name="content_analyzer2" another-key="id12"> <type="global" /> </table> ...
0
votes
3answers
78 views

Print start and end between two patterns excluding end of range [duplicate]

I want to use sed -n "/START PATTERN/,/END PATTERN/p" file.txt pattern to search in a file. file.txt content is ~keyword~, ~output~. ~1.~ ~output~. ~2.~ ~output~. ~keyword~, ~output~. ~1.~ ~output~. ...
1
vote
2answers
40 views

Merge 2 files in one with a customized line in between

I have 2 Files A and B. I want to merge them in File C with a customized line in between. File A: Hello File B: Hi The merged file should contain: Records in File A is Hello Records in File B ...
3
votes
3answers
80 views

Replace multiple lines with a string when the line numbers are stored in a file

I have a file with few million lines, all the same. just for an example: Known Known Known Known Known Known ... I have another file with few thousand line numbers, for an example: 3 5 6 ... I ...
3
votes
3answers
120 views

Add mtime to grep -c output and sort the output by mtime

I have a directory full of logs named in the following style: info.log00001 info.log00002 info.log00003 ... info.log09999 info.log My current output (using grep -c) I need to analyze the ...
-1
votes
2answers
30 views

Search and output string from a file to xml

Received timestamp=1459434658969: ABC: Field id=0 double 11.4 DEF: Field id=1 string >def< GHI: Field id=2 string >g_hi< I would like to read a file that contains input in the above ...
1
vote
2answers
44 views

Compare 1st column of the 1st file and 2nd column of the 2nd file and get the the output as following [duplicate]

File1: Excel file (.xls) UN ID St M1 M2 SE DOF PV PA FC 17127159 0 -5.9 297.3 765.7 0.22 4 0.003 0.00389231 2.57536 17127163 2 ...
2
votes
3answers
64 views

Splitting file based on last digit of first column in UNIX

I have a file sales_$date.csv. I want to split it into 10 files based on the last digit of first column (ITEM). so in reality file would be split in 10 files as sales_$date-01.csv, ...
2
votes
3answers
35 views

`pwd`, but omit first n directories

pwd gives the full path of the current directory, for example: /first/second/third/anotherdir/thefinaldirectory How can I omit the first n, let's say three directories, so that only ...
0
votes
1answer
53 views

Compare 1st column of the 1st file and 2nd column of the 2nd file and matching

File1: Excel file (.xls) UN ID St M1 M2 SE DOF PV PA FC 17127159 0 -5.9 297.3 765.7 0.22 4 0.003 0.00389231 2.57536 17127163 2 ...
1
vote
1answer
34 views

Interactive remove files listed with paths in text file

I am trying to interactively remove files listed with their paths in a text file. The command I am trying is: xargs rm -i <filelist.txt The error I get is: rm cannot remove ...