General :: Parsing Delimited File And Variable Scripting?

Sep 23, 2010

I did some searches and after a few hours was able to get what I needed. What I didn't find was a fully encompased means of what I'm used to in the windows world in working with delimted files. Hopefully this is helpful to others and if there is something better or leaner way, even better.We have an issue where managing printers, just viewing on RHEL w/ sys-conf-prtr we lose any number of, up to ~30 printers from lpadmin. Rather than stare and compare to find the missing ones, I wanted to make an intuitive script. This is what I came up with.

while IFS="," read Prntr IP; do


View 3 Replies


Programming :: Bash Scripting - Parsing Text File By Character

Aug 11, 2009

Is there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?

View 13 Replies View Related

Programming :: Bash A Value From A File Then Assign To Variable?

Feb 27, 2011

At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3

View 9 Replies View Related

General :: Output Pid's From Ps To A Comma Delimited File?

Apr 7, 2010

need to monitor pecific processes over a time frame in terms of the amount of memory and cpu usage it utilizes. I can do this using the top -p <pid> option and using ps to retrieve the pid's. However, seeing that the pid's might differ and it needs to be run on about 13 different machines, I would like to write a script for this that can be run at set intervals. My problem that I have is this:

- When running top -p <pid> I can specify a comma seperated list of the processes required to monitor at that specific time.

- I can use ps -ef | grep <process> | grep -v grep| awk '{ print $2 }' to retrive the list of pid's and output this to a file.

However, how can I output these to the file as a comma seperated list without having to manually do this every time? The reason for this is (an example), lets say I want to monitor the cpu and memory usage of postgresql as well as all its child processes, then I would ps grep for postgres and get the list of pid's for instance.This list then needs to be passed to top -p as a comma seperated list of pid's I suspect that awk or sed might have some options available for this but I do not know this well enough.

View 11 Replies View Related

General :: Count An Item In A Tab-delimited Txt File?

Mar 6, 2010

in a tab-delimited file, such as:



View 3 Replies View Related

General :: Check Quality Of A Specific Column In A Tab-delimited File?

Mar 8, 2010

shell commands for such two goals?

In a tab-delimited file,


1. How can I find the non-unique values in the 1st column (1, in this case)?

2. How can I find the non-integer values in the 5th column (abc, in this case)?

View 3 Replies View Related

Programming :: Bash Variable Parsing / Extract And Put Into Variables Each Combination Of F1 And F2 In A Loop?

Oct 14, 2010

I have a bash variable where the content looks like this where ;f1; and ;f2; are delimiters:
;f1;field1value1;f2;field2 value1 ;f1;field1value2;f2;field2 value2 ;f1;field1value3;f2;field2 value3

So what I need is to extract and put into variables each combination of f1 and f2 in a loop to something like that:

#first pass of the loop I need:
f2=field2 value1

#second pass of the loop I need:
f2=field2 value2

# third pass of the loop I need:
f2=field2 value3

View 15 Replies View Related

General :: Parsing File Dates - Get The Date Of The Last Time A File Was Modified ?

Jan 11, 2010

I need to get the modified date on a file in linux to use in a script.I tried using 'ls -l' on the file, but this caused problems when the date turned from a single digit into a double. The reason for the problem was because I was parsing the result string on spaces.How can I get the date of the last time a file was modified so I can use it in a script? For example, if a file was modified on 1/11/2010, I need the 11.

View 2 Replies View Related

Software :: Rear File Names To Creat A Comma Delimited File?

May 22, 2010

I am looking for an application that will read the file names in a folder and generate a comma delimited file. I want then to import the comma delimited file contests to a spread sheet such as open office.I hava a number of PDF files generated from a scanner, each file with its own scaner generated file name. I want to put these into a data base so I can add the title and other reference information to provide a data base.

View 7 Replies View Related

Software :: Scripting : Using A Variable In A Command?

Jan 13, 2009

I need to create a zip file of jpg and bmp files. The zip file is named after the first file it finds which ends with .dat. Here is my script:


DAT_FILE= `find . -maxdepth 1 -iname "*.dat" | head -1 | sed 's/..(.*)..../1/'`
(cd pics; find . ( -name "*.bmp" -o -name "*.jpg" ) -print | zip ../$DAT_FILE -@ )

BTW my sed command cut off the first two chars and last four chars since find will return the filename is the form of "./filename.dat" and I just want to extract filename. When I run this script, it creates a zip file named ".zip". How do I fix this so the zip file is named after my dat file?

View 3 Replies View Related

General :: Parsing A File Into Database?

Jul 14, 2010

parsing the text file in perl.I have very large text file with plenty of columns and can i parse the file into Oracle database.

View 3 Replies View Related

General :: Parsing A Binary File?

Mar 17, 2011

Is it possible to parse through a binary file using a script using either Korn shell or Bash

View 3 Replies View Related

General :: Parsing File With Multiple Delimiters?

Jun 21, 2011

I am using nessus to scan systems, and it generates the report file without any specific delimiter. Shown below is how a typical line in the file reads (It might show up as a very long line.


xx.xx.xx.xx|cpq-wbem (2301/tcp)|49272|REPORT|Synopsis :;;The remote web server is affected by multiple vulnerabilities.;;Description :;;According to its self-reported version number, the HP System;Management Homepage install on the remote host is earlier than 6.2. ;Such versions are reportedly affected by the following ;vulnerabilities :;; - Session renegotiations are not handled properly, which; could be exploited to insert


The field of interest (for me) are IP ADDRESS, Synopsys, Description, Solution and Risk Factor. I tried the following command to parse this:


sed s/:;;/|/g report.nsr | grep Risk Factor |High | awk 'BEGIN {FS = "[:][;][;]"} {printf("%s|%s|%s|%s",$1, $6, $7, $10)}'

But this would not give desired results as ':;;' is not a standard delimiter and hence gives incorrect results. how to grab everything that occurs between the strings 'Synopsys', 'Description', 'Solution' & 'Risk factor' in the above example? In other words i may be asking to use multiple delimiters.. in the order of occurance.. is there a tool that supports multiple delimiters?

View 7 Replies View Related

General :: Parsing Output - End Of File Option ?

Feb 23, 2011

I'm working on a alias/script that will make it easier to look at my environment via the set command.

On my ubunto when running set it also displays some 10 pages of code pertaining to something called "imagemagik". at the end of the output. This code begins with the { character.

This is annoying if I want to look at my environment when working on scripts. How could I use something like grep, awk, sed, or whatever to ignore everything after the "{" character.

That seems to be the simplest way as long as there are no leading brackets in my environment. (And if you're thinking I should just remove {imagemagik}, I might just do that. But I still would like to know how to do this).

View 3 Replies View Related

Programming :: Searching Pattern In Tab Delimited File Using Grep

Mar 4, 2010

Suppose i have a file(1.txt) separated by TAB delimiter in a line

1 B AB 2
2 C AB 2

if I need to search for the records having B?? using grep.If i need to perform multiple search like line having "C and AB" or "B and AB"??

View 5 Replies View Related

Programming :: Using Sed To Remove Line In A Comma-delimited File?

Mar 10, 2009

I have a script that output all my data in to a comma-delimited file separated by ";"

Current Output:


"SAP 1117A";;;0;0;0;0;0;3;;""


I would like to remove all lines that have an NA in the second field.

New Output


"SAP 1117A";;;0;0;0;0;0;3;;""

View 4 Replies View Related

General :: Parsing Through A Nagios Config File To Extract Info W/ Sed - Awk - Vi

Oct 13, 2010

I have a config file called hosts.cfg.

It contains entries like this:


There are many more of these entries in the file, over 500, all in this same format: each host has a "define host" followed by 18 directives contained in squiggly brackets.

If I want to know all the hosts that are in the hostgroup called SERVER_GRP, I suppose I would need to read every hostgroups line (8th directive in squiggly brackets) that contains SERVER_GRP and output the corresponding host_name line (1st directive in squiggly brackets) from that entry.

View 3 Replies View Related

Programming :: Pasting Multiple Cut Outputs To A Tab Delimited Output File?

Sep 4, 2010

I have a requirement like this:Cut the characters from each line of a file with following positions: 21-24, 25-34 ,111-120.Thse fields now need to be placed in a tab delimited output file.Currently this is how I am achieving it:

cat newsmaple.txt | cut -c 21-24 > out1.txt
cat newsmaple.txt | cut -c 25-34 >out2.txt


View 1 Replies View Related

Programming :: Bash - Reading Csv Delimited File To Array And For Further Manipulation?

Jan 6, 2010

I am trying to do this:

1. Read csv delimited file line1 and store all values in array

2. Use the values stored in the array and replace values in other text file with them

3. read line2 in the cvs file and repeat the process

4. Do above for all lines in the cvs file

for example:

file1.cvs content:

text1,text2,text3,"text 4"
a1,a2,3,"a 4"

file.txt content:

some text $array1$ some text
some text $array2$ some text

1. read line 1 - text1,text2,text3,"text 4" put each value in array X[] lines that contain spaces in cvs will have double quotes

2. read x[1] and replace value $array1$ (in file.txt) with x[1]read x[2] and replace value $array2$ (in file.txt) with x[2] and so on

Can above be accomplished in BASH and how?

View 1 Replies View Related

Programming :: Move Line Of Pipe Delimited Flat File If Field 27 = Sold?

Sep 26, 2010

I have a pipe delimited flat file, field 27 is price. I would like to move items marked sold to a new file every couple months.

awk -F"|" '$27 == "SOLD" {print $0}' >>

Allows me to write line to new file but I need to delete the original line, I also want to make sold case insensitive tried [Ss][Oo] with no luck

View 4 Replies View Related

General :: Shell Scripting - For Each File In Directory

May 2, 2011

I am working on some homework, however i am not here to be spoon fed. I am trying to get the numerical modification date of each file in a folder. Ie lets say there is a file called bob and it was modified 2006-11-23. i want to get it into a variable as 20061123.

Now i currently have this code:


However for some reason my output is:


See how the 2011 has been placed next to it? i ran it with -x and saw this:


However i do not know how to find a way around this?

View 11 Replies View Related

General :: Shell Scripting Text File Creation ?

Feb 16, 2011

I'm just starting out with shell-scripting, but having a problem with making new text files with the touch or cat > commands.

What I've been doing is touch testfile1.txt

Also, I've tried cat > testfile1.txt (text)

Console reports "bash: text1.txt: No such file or directory. Consfusingly, it works fine in the home-directory. But if I move the file to where I want it, I can no longer view, edit, etc. it.

View 1 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

Aug 21, 2009

I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.

For example:


Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).

View 6 Replies View Related

General :: Scripting - Move A List From A Text File To Directory ?

Jan 10, 2011

I'm sure I've done this before and am having a brain fart.

I have run into this a couple of time this last month:

I have a list of torrent files (blahblahhexblah.torrent) saved in a text file. I would like to read the text file and populate the client directory.

I can echo the file using:

But I cannot remember how to pipe the output into the directory, nor can I find any resources that describe the process.

Interestingly enough, I've had a couple of opportunities to do similar tasks with passwords and privileges and even across the LAN in the last few days. Solving this problem will help me solve the others for next time.

View 2 Replies View Related

General :: Delete A File On A Remote Server Using Shell Scripting?

Jul 18, 2010

delete a file on a remote server using shell scripting.

View 14 Replies View Related

Software :: Get Variable From Text File Into Bash Variable?

Jun 10, 2009

I have a text file i that has a mailTo: NAME in it. In a bash script i need to extract NAME and put it in a $variable to use. How do i do this?

View 2 Replies View Related

General :: Shell Scripting: Inserting Text Into A File Name With A Predictable Pattern

Apr 18, 2011

Just using shell scripting, how can I insert text into the middle of a file name. The file has a predictable pattern, let's say 3 letters and 3 numbers and I want to insert text in the middle of those 2 patterns. Say ABC123 is the file name. As a result, the file name should be ABC.blah.123

View 2 Replies View Related

Programming :: Parsing Xml File Using Shell Script And Generate Report In A PDF File?

Jul 9, 2009

parsing xml file using shell script and generate report in a PDF file

Xml file input:

<student name="x" father name="x1" class="first" Address="xyz">
<property name="sports" value="yes"/>
<property name="drawing" value="no"/>


View 12 Replies View Related

Software :: Export A Variable To Parent Shell In Shell Scripting?

May 21, 2009

Is there a way to export a variable to parent shell in shell scripting ?

View 3 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:



Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:


View 3 Replies View Related

Copyrights 2005-15, All rights reserved