Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

1
vote
3answers
23 views

How do I organize and cut this portion of a directory into a file?

I'm new to unix and I'm not sure how to name my title but my main objective is to copy the contents of a directory and send it to a file. Then cut out the directory location to just have the name. ...
2
votes
4answers
78 views

How to move to the “Nth” offset in a file

I'm in need of a command that would help me to the the N th offset in a file. Say this is my file's contents: [root@localhost ~]# cat /file1.txt this is the the first line of many lines and is just a ...
0
votes
0answers
11 views

How to read fields of a text block?

I would like to create sql inserts based on Radius log fields. For example, I have these two types of accounting logs and I'd like to convert each text block to an insert like below: INSERT INTO ...
5
votes
5answers
2k views

Sort input file by the results of a regex

I'd like to sort a file based on the results of a regex expression. For example, if I have the following property declarations in Obj-C @property (nonatomic, strong) id <AlbumArtDelegate, ...
1
vote
2answers
25 views

Text processing - Building a slurm topology.conf file from ibnetdiscover output

First things first: no knowledge of either slurm or Infiniband is required - this is a purely text processing problem. Second - I'm aware of ib2slurm - the code is somehow broken and quite possibly ...
0
votes
0answers
14 views

Create Paragraph Numbers in Roxterm

I have a text file created in Roxterm. I need to number the paragraphs. So, for instance, the first paragraph would be labeled 1 and so on. Is there a command to do this? My text file is called ...
6
votes
10answers
6k views

Copy only Specific text of a file to another

I have a file abc.txt the contents are <classpathentry kind="src" path="Sources"/> <classpathentry kind="con" path="WOFramework/ERExtensions"/> <classpathentry kind="con" ...
4
votes
4answers
2k views

Match two words that is on the same line

The command that I have prints out two of the lines whenever FW_6.0.0 is found, below is the code: grep -oP 'FW_6.0.0, (.*)$' file Below is the output, both has the same value of FW_6.0.0 ...
58
votes
10answers
74k views

Looping through files with spaces in the names?

I wrote the following script to diff the outputs of two directores with all the same files in them as such: #!/bin/bash for file in `find . -name "*.csv"` do echo "file = $file"; diff ...
10
votes
5answers
761 views

How to print file content only if the first line matches a certain pattern?

I am writing a script, I want to check if the first line of the file matches a certain pattern and if it does then print out the file. How can I achieve this? How do I check for pattern? Is there a ...
1
vote
3answers
71 views

Split a file based on required string

I have test file with the below contents: CREATE TABLE XYZ ( ABC INT, CDE CHAR(10), . . . ); Similarly, REPLACE VIEW XYZ ( ABC, CDE, EFG ); CREATE TABLE XYZ_1 ( ABC INT, CDE CHAR(10), . . . ); ...
4
votes
2answers
60 views

Search directories for multi line string

Looking for a way to recursively search a repository for all files containing a multi line string and return the file names that contain it. The paragraph is just a header approx 30 lines. So I know ...
4
votes
3answers
4k views

Skip first 3 byte of a file

I am using AIX 6.1 ksh shell I want to use one liner to do something like this cat A_FILE | skip-first-3-bytes-of-the-file I want to skip the first 3 bytes of the first line, is there a way to ...
2
votes
2answers
23 views

How to sort data by the numbers in third column? [duplicate]

If I have a file consisting of data that looks as follows, how would I sort the data based on the numbers in the 3rd column ? The space between the first two columns are NOT tab delimited but some ...
2
votes
2answers
51 views

How do I remove all but the last occurrence of a string?

I am trying to remove all occurrences of 2016/01/30 14:52:51: but the last one. I tried this: awk '{gsub(//,"2016/01/30 14:52:51: ",$1);print}' to replace all but the last occurrence with nothing, ...
1
vote
3answers
67 views

Trim a specific field and replace in Unix Shell Script

I have a file with below data: 5773|2015-11-19|2016418|O|2015-11-06|C|AB1CD|826|826|CDE|2015-11-19|22222222222222222222222222222|ABCD|AB|30 ...
1
vote
1answer
34 views

splitting file based on values in specific column

I have a file that I would like to break up into multiple files with uniq values for the first column. For example, here is a file: fileA.txt 1 Cat 1 Dog 1 Frog 2 Boy 2 Girl 3 ...
10
votes
3answers
14k views

How do I insert a space every four characters in a long line?

I've got a long line that I want to insert a space every 4 characters, on a single lone line of solid text to make it easier to read, what's the simplest way to do this? also I should be able to input ...
0
votes
3answers
35 views

How can I parse a multi-line command output in bash?

I have a command that outputs the following: Some text here 1,3456: "Descr 1" 2,7891: "Descr 2" 3,0976: "Descr 3" Some other random text here I want to write a bash script that parses ...
5
votes
2answers
61 views

How to find one word and sequentially replace it?

I am running AIX 5.3(not by choice, but I cannot change it), and I have a text file: servers.txt Here is an example of the file's contents: apple port1 username password IPAddress TCP banana port2 ...
0
votes
1answer
74 views

How do I grep the lines based on '.' (dot)? [duplicate]

Suppose I've file with the following contents: 123 251 7.8 951 Now I want to grep the lines having . I've tried: $ cat file | grep . 123 251 7.8 951 $ cat file | grep '.' 123 251 7.8 951 But ...
-1
votes
1answer
46 views

converting plain text information to csv or excel

I have file containing similar data, which i am trying to arrange in the similar way, below are the details. I modified the script as per the variables in the context unable to get the required ...
1
vote
2answers
74 views

Compare columns from two CSVs and merge on matches

I have two CSV files and am trying to merge them based on the first column in the first file matching the third column in the second file. They lines are not sorted. file1.csv: android,1,2 osx,2,5 ...
1
vote
1answer
35 views

Read each line - BASH

my goal is to store each foliated line (actually each rule) into an array. My output: Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT ...
34
votes
14answers
12k views

A standard tool to convert a byte-count into human KiB MiB etc; like du, ls1

Is there a standard tool which converts an integer count of Bytes into a human-readable count of the largest possible unit-size, while keeping the numeric value between 1.00 and 1023.99 ? I have my ...
33
votes
8answers
8k views

Is there a way to modify a file in-place?

I have a fairly large file (35Gb), and I would like to filter this file in situ (i.e. I don't have enough disk space for another file), specifically I want to grep and ignore some patterns — is there ...
1
vote
1answer
36 views

cut column range sed/awk/cat

I'd like to cut a certain range of text (i.e. characters 17-63) repeatedly from a *.txt file, which is several thousand lines long. One line looks like this: ...
0
votes
2answers
43 views

Automatic Paragraph Numbering [on hold]

I have a text file and would like to modify it so that it automatically numbers the paragraphs as seen below. Please make your solutions as simple as possible as I am a novice when it comes to the ...
3
votes
3answers
135 views

Retrieving lines from a file depending on other lines

Imagine the following file structure: foo.bar.1 blabla moreblabla relevant=yes foo.bar.2 relevant=no foo.bar.3 blablabla foo.bar.4 relevant=yes I want to retrieve all foo.bar lines where within the ...
7
votes
7answers
349 views

Convert rows to columns

I have a file that includes details about VMs running in a hypervisor. We run some command and redirect the output to a file. And the is data available in the below format. Virtual Machine : OL6U5 ...
2
votes
4answers
117 views

How to delete everything after a certain pattern or a string in a file?

Suppose I have a list of URLs in a text file: google.com/funny unix.stackexchange.com/questions isuckatunix.com/ireallydo I want to delete everything that comes after '.com'. Expected Results: ...
1
vote
1answer
35 views

replace unix path inside a file

I have a sql file of a wordpress database. I am moving to another server which the document root is different. The old document root was /home/saeid/public_html The new document root is ...
0
votes
2answers
1k views

Sum two columns from different files

I have two files like this: File1: -54.005 -67.405 0.1 -54.05 -68.7833 0.2 -54.05 -68.7333 0.3 File2: -54.005 -67.4050 70 12.7 -54.05 -68.7833 167 12.5 -54.05 -68.7333 205 12.6 ...
1
vote
1answer
36 views

Test length of string in file

I am not sure if I am using my argument correctly. I would like to pass in a argument which is a text file containing a string. When I run this script, it always enters the if statement even when the ...
10
votes
8answers
283 views

sed in-place line deletion on full filesystem?

Due to an application bug as yet undiagnosed, I have several hundred servers with a full disk. There is one file that has been filled up with duplicate lines—not a log file, but a user environment ...
2
votes
2answers
1k views

How do I move a line in a text file up or down by one line?

I have some text files, and I'd like to be able to move an arbitrary line in any of the files up or down one line (lines at the beginning or end of the file would stay where they are). I have some ...
1
vote
2answers
66 views

Select filename with highest version number

highestVersion() { for TEST_PATH in `ls -a "$/TEMP"/*.flg` do echo " you are here" TEST_FILE=`basename "$TEST_PATH"` echo "$TEST_FILE" done } Below is the file ...
1
vote
2answers
37 views

How to replace string within parenthesis using using sed

I have the following string: col1|col2|col3+++++++++++A|1|a B|2|b C|3|c D|4|d (3 rows) I want to split this string so as to remove the string in the beginning till the last + symbol and then ...
1
vote
2answers
46 views

Add columns to a text file with set spacing in Bash

I am setting up a malware zone file in DNS which will point all hosts to a specific IP. The file is simply a list of hostnames. This is what I have now: googlle.in ...
12
votes
8answers
918 views

Remove extra header lines from file, except for the first line

I have a file that looks like this toy example. My actual file has 4 million lines, about 10 of which I need to delete. ID Data1 Data2 1 100 100 2 100 200 3 200 100 ID Data1 ...
1
vote
1answer
20 views

Merging text file directories

I have two directories: Libc-825 and Libc-1044. Imagine that version 1044 is newer, but buggy. Is there a way to merge these file trees? I have there C sources with not so big differences. I have ...
1
vote
3answers
38 views

Transpose paramter values from a file and Generate parameter files from it

There's a file containing a table with the parameter names as the first line, values in the following lines: How to perform the following using awk, sed or any shell scripting utility: generate a ...
1
vote
2answers
31 views

awk alter the next line after a pattern match based on another pattern match

I have a file with lines such as: .... pattern1 100 200 300 pattern2 300 400 400 pattern1 300 900 700 pattern1 200 500 900 ... As shown in the above example, there are some lines where pattern2 ...
0
votes
1answer
38 views

How do I remove “^M” from a file? [duplicate]

I have two "identical" files that I compare in diff, and it shows that every line is different, after looking at the file I found that one of them has ^M at the end of every line. How do I remove ...
1
vote
1answer
43 views

transpose sets of three rows to columns

I have a file that has below entries: [root@ovmm329 ovm_utils]# cat /tmp/disk.txt Physical Disk : 'IBM (67) device=/dev/mapper/360050768018206483000000000000453 shareddisk=true Physical Disk : 'IBM ...
0
votes
2answers
19 views

sed + search word with strings and replaced all word

I want to create with sed the following: For example each word in the file that have the ssss... Should be replaced (all word) with target string as gggg. echo "duwdbnhb ssssssmnfkejfnei" | sed ...
0
votes
1answer
18 views

Insert Line in File When Group of Lines Changes

Let's say I have a text file like this: group1 hello group1 there group1 nice line group2 here group2 we group2 go What I want to do is insert a line when the group of lines changes, something ...
1
vote
3answers
36 views

How to join two files by matching a column with an irregular number of columns?

file1: 0000002|SLM DEV CORP |PO 857 0000003|S TOPPING |APT 19 0000004|JD BROS LTD ...
5
votes
5answers
331 views

How to group lines in file by two?

I have a text file like this: a b c d e f g How can I group those lines to obtain an output like this: a-b b-c c-d d-e e-f f-g I have to do this in shell (sh, csh, bash). I have found this: ...
0
votes
1answer
41 views

sed appending filenames on newline

I am trying to add filenames to many *txt files, which are tab-seperated (they will eventually be joined together using cat) I am using bash, on Ubuntu 14.04. So far my code is; for f in *.txt do ...