Manipulation of text by programs, scripts, etc.
4
votes
3answers
83 views
Using Linux text editor to prepare content for Microsoft Word
I need to prepare a long manuscript that must be submitted in a Microsoft Word document in order to meet the submission criteria. (Please no "Don't use Word" comments.)
I want to use a text editor on ...
4
votes
2answers
49 views
How to add a line from a list into another file when a specified line is found?
Basically I have 2 files. One has a list of router and switch login prompts, like this:
user@router1
user@router2
user@switch1
user@switch2
The other file has blocks of XML, like this:
...
5
votes
2answers
77 views
awk + paste for cleaning up PATH?
I have seen this code in .cshrc init files on a few machines. I went through a few awk tutorials in trying to understand how it works, but I am still unable to decrypt it.
setenv PATH `echo $PATH | ...
2
votes
3answers
37 views
Replace certain strings with value from former line
I have the following text:
Source IP,URL
1.1.1.1,example1.com
Blank,example2.com
2.2.2.2,example3.com
Blank,example4.com
Blank,example5.com
Blank,example6.com
Blank,example7.com
7.7.7.7,example8.com
...
3
votes
3answers
75 views
sed + how to remove character/s that start or ended on each number
How do I remove the . character(s) that start in the beginning of each number or end on each number?
Remark – perl one liner also good alternative for sed.
Example input:
.23.12.44.5.
.233.3.3.3
...
3
votes
3answers
67 views
checking data in columns when a data or some may be missing or present?
I am not sure if this possible.
say i have columns like :
Team Colour Game Rainfall PlayerName
XYZ Blue Cricket Yes Kapil
suppose i need to search ...
4
votes
2answers
119 views
sort part of a file
How can I sort the file by the second column from the terminal. The content of the file is:
Nome Note
------------
Mehdi 0
Sunday 20
Others 10
Shnou 5
Using sort -t' ' -nk2 is not ...
4
votes
3answers
81 views
Why is sed giving me an error about an unterminated `s'?
I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like:
sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
6
votes
1answer
56 views
How to do `head` and `tail` on null-delimited input in bash?
find command can output names of files as a null-delimited strings (if -print0 is provided), and xargs can consume them with -0 option turned on. But in between, it's hard to manipulate that ...
1
vote
2answers
83 views
shell script to do some text manipulation of text file data structure and slight content changes
Apologies in advance for the wall of text, not sure how else to represent the existing data structure.
I have been handed about a years worth of logs collected every hour from a server.
Sadly, ...
1
vote
1answer
45 views
Using awk to parse AIX's lsuser output in stanza format
I'm creating a simple awk script to parse AIX's lsuser -f ALL output and return information in one line. A sample of the output is something like this.
root:
id=0
pgrp=something
...
1
vote
2answers
35 views
Better string escaping for hg
So periodically I remove files that are listed as missing by the version control system hg. What I've noticed is that this (admittedly ugly) script I have does not properly escape strings:
hg status ...
2
votes
6answers
88 views
How can I separate these two outputs using awk command
Here's my output:
MessageID=3990592283244651750-30192b51.13df831d93a.7eb4;EsbTiming=2013-04-12T01:07:46.099
I want only the time.
How can I separate them?
4
votes
6answers
91 views
Getting two fields from same line together
I've got a situation where I've got several lines, and I need two different fields out of each of them. To be specific, I have a list of references in a bibliography and I want to get the last name ...
3
votes
3answers
94 views
Split file into multiple small files, separate by the newline symbol
Is there a utility that split file by newline symbol? e.g if a file contains the following lines,
aa
bbb
cccc
If I want to split it to 3 files, the desired output would be:
aa, bbb And cccc (in 3 ...
2
votes
3answers
62 views
Scripting to domain allocation to server
I have two text files:
file #1: domain.txt
cocacola.com
airtel.com
pepsi.com
file #2: servers.txt
192.0.53.42 , 4 # 4 domains already allocated on server 192.0.53.42
192.53.1.2 , 1 # 1 ...
2
votes
3answers
125 views
How can I use SED or AWK to replace placeholders in a template file with variable content that contains special characters?
CentOS 6.3
I'm trying to get a small script to send an email containing a copy of email headers in the body (for the purpose of internal reporting).
The template file contains the following:
...
4
votes
3answers
63 views
Replace all the occurences of a term in the files contained in a folder
In a folder on my system, I have a C++ project that I'm trying to compile.
This process uses some C++ idioms which are not supported by my compiler version. In particular, often inside the code it is ...
3
votes
1answer
44 views
tac command's option creates strange output [comprehension question]
Say I have this file, containing nothing than
a
b
c
b
a
Using tac --separator=a file in BASH [on a Debian based Linux], I get this:
# empty line
# empty line
b
...
0
votes
1answer
99 views
comparing lines with awk vs while read line
I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line ...
3
votes
2answers
76 views
How to adjust column width in Linux command output
When I used this command on Red Hat Linux
/usr/sbin/ss -i
I get the following output below:
State Recv-Q Send-Q Local Address:Port ...
3
votes
2answers
54 views
Can I make grep treat escaped multiline as a single line?
How can I make tools like grep treat multilines escaped with a backslash as a long single line?
Let's say I have some files that looks like this:
testvar=test1 \
test2 \
test3
...
0
votes
0answers
24 views
sybase and iconv
I inherited an old Ubuntu 6.10 server running php 5.1.6 which is using sybase to connect to MSSQL. A user submitted some text containing an en-dash and crashed one of my script. It turns out sybase ...
1
vote
3answers
64 views
awk + print line only if the first field start with string as Linux1
how to print the line in case the first field start with Linux1
for example:
echo Linux1_ver2 12542 kernel-update | awk '{if ($1 ~ Linux1 ) print $0;}'
the target is to print the line , ...
1
vote
2answers
125 views
Unix command for pattern matching
I want to count the number of words and print the matched pattern lines which matches exactly with following pattern:
abc-ERROR:
The input File contains:
# abc-ERROR: xyxxkkfgfr
# def-Error: ...
4
votes
4answers
103 views
How to remove character and space from a string
Hello I have one file with output
Name : ABC
Name : CDE
Name : ZYS
I want to get the result
ABC
CDE
ZYS
How can i get it through SED command.
I have tried. sed s/'Name' but ...
9
votes
3answers
296 views
Deleting all C comments with sed
I am trying to write a script that will delete all comments and everything in between inside C files in my current directory. I've been using sed, and this is what I have so far:
sed -i '/ * [^()] ...
0
votes
2answers
34 views
How to delete lines where the given part of the line is more than 100 chars?
I know I can delete lines that are longer than 100 chars with this:
sed '/^.\{100\}..*/d'
But I have the following example line:
<a ...
0
votes
1answer
56 views
read line by line and take a string in line and assign that string to the subsequent line using perl
Data file is fixed length file, and I want to read file line by line and take a string from the current line, and then append that string to the subsequent line and write into another file.
For ...
2
votes
2answers
83 views
add “#” in begining to selected lines in File
Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B
File A
abcd
abdc
sdfg
asdfa
jon
ram
File B
jon
abcd
grep file B from file A and add "#" ...
0
votes
2answers
70 views
read file record by record and do transformation to the subsequent record based on above record and write into another file
Data file is fixed length file, and I want to read the file record by record and do transformations to the subsequent records based on the prior records (and write the results into another file).
...
-4
votes
1answer
49 views
How to transform two delimited ASCII files
These are 2 common delimited, text file transformation problems I'd like to find scripts to do (I dont know if awk or perl is best for these tasks).
csh is the default shell on my Solaris10 unix ...
1
vote
2answers
93 views
How to record every transaction using Bash
I have a file with debit credit and withdrawal transactions. I need a bash script that records the balance after every transaction. So file is like this:
D:11/02/12:1000.50
C:11/03/12:300
...
1
vote
4answers
182 views
print last field from line + alternative for awk
Due to technical reason on my Solaris machine, I can't use awk in order to print the last field in line.
What are the other alternatives to awk that print the last field from line (using cut or tr ...
1
vote
2answers
86 views
Regex and piped commands with sed
I'm finding really hard to use sed command, plus I can't seem to find well written tutorials.
Let me say that I worked with regular expression in other languages (Python, JavaScript, Java), so that ...
6
votes
7answers
623 views
Slick one-liner to convert a list like “1: 2, 3, 4, 5” to “1.2, 1.3, 1.4, 1.5”
Let's say I have a file that looks something like this:
23: a, b, c, d
24: b, d, f
25: c, g
and I want to get output like this:
23.a
23.b
23.c
23.d
24.b
24.d
24.f
25.c
25.g
Of course it's not ...
3
votes
2answers
102 views
I need a text editor to edit/visualize >10GB text files
So as to vizualize, and hopefully edit, a very large text file, more than 10GBytes (a backup dump of whole database), I have tried using vim... it didn't behave very well.
I have also tried cat to at ...
3
votes
1answer
42 views
How to edit files in-place while performing operation on the values matching the searched pattern?
Given a list files containing random text and many datetimes in ISO format in it (e.g "2012-07-02T10:47:24+02:00"), how can I find all these datetimes and add 2 hours to each one ?
Ideally a solution ...
1
vote
3answers
75 views
Get separate used memory info from free -m comand
As a output of free -m command I got following.
total used free shared buffers cached
Mem: 2496 2260 236 0 5 438
-/+ ...
1
vote
3answers
165 views
How to get data count between two strings with multiple occurences in the same file
I have the data in my file as
START-OF-FIELDS
ID
NAME
DEPT
END-OF-FIELDS
START-OF-DATA
1|joy|cs
2|sam|ec
END-OF-DATA
START-OF-FIELDS
ID
NAME
DOB
DEPT
ADDRESS
END-OF-FIELDS
START-OF-DATA
...
2
votes
1answer
59 views
Best way to remove lines from a file where matching text (not whole line) exists in another file
I have a file of email addresses (file 1)
and another file (file 2) of lines of data that contain some of these email addresses
I want to compare files and remove all lines in file 2 that have a ...
0
votes
1answer
161 views
How can I find and filter a specific column in a .csv file? [duplicate]
I have .csv files with the following structure:
cat,dog,mouse,pig,bird,cow,...
21,34,54,566,78,1,...
23,10,12,569,56,4,...
32,20,13,123,56,3,...
34,30,44,322,66,2,...
I want to filter the column ...
4
votes
4answers
255 views
Count lines matching pattern and matching previous line
I want to count the number of times that a role is successfully deleted. The problem is that one line of the log file will show that the script is about to delete the role:
Prepare to remove role X
...
1
vote
2answers
65 views
Match ids and print original file
I have two files
Original: (5000 entries)
Chr Position
chr1 879108
chr1 881918
chr1 896874
…
and a file with allele frequencies (2000 entries)
Chr Position MAF
chr1 881918 0.007
...
0
votes
1answer
46 views
Help with understanding a regular expression
I have this regular expression \\..\\{3\\}$
I want to understand how this expression works to match a string. My thought is that it matches any 8 characters at the end of the line. Is that how this ...
3
votes
2answers
90 views
Concatenate block of lines with following block of lines
I am trying to process some text exported from lecture slides using pdf2text. The bullet points of some slides show up like this:
title for the list
-
-
-
a bullet point text
another bullet point ...
2
votes
2answers
116 views
Extract Data between comma
I have an output file which contains different numbers seperated by commas. But the issue is I do not know the number of commas.
I would in turn like this data to be grep on another file. For ...
2
votes
3answers
96 views
Linux command line that will fail if any standard out is produced
Is there a simple utility which I can pipe output to on Linux that will:
Return a success code if there is no output on standard out (and / or standard error).
Return a failure code if output is ...
5
votes
3answers
86 views
Filtering redundant paths from a list of paths
I have a list of relative paths such as this:
dir1
dir2
dir2/dir3
dir2/file1
dir3/file2
dir3/dir4
dir3/dir4/file3
In the example above, the specifier dir2/file1 (for example) is redundant, because ...
2
votes
2answers
291 views
How can I replace text after a specific word using sed?
I have a file named .ignore. In need to replace the projdir. For example:
ignore \..*
ignore README
projdir Snake
I need to replace Snake with, for example, "PacMan". I read the man page, but I ...



