Sponsored Content
Homework and Emergencies Homework & Coursework Questions String editing using sed? awk? Post 302370666 by bakunin on Thursday 12th of November 2009 05:26:11 AM
Old 11-12-2009
Quote:
Originally Posted by peage1475
Thanks alot, and I would much rather learn myself than be spoon fed since I like this kind of stuff.
Excellent! This is the right attitude.

Quote:
Originally Posted by peage1475
Ok im already having trouble. I can create a file that lists all the users;
Ok, but where do you get the information? In your original find-command you have searched certain directories and this will give you the users only if you know for sure that all the users you search have their home directories there. Is there a data structure in a Unix system which lists all the users and their home directories?

Ok, here is a tip: if in troubles, consult the "man-pages". Everybody does it (Unix expertise is about to know where to look rather than knowing everything.) There is especially one command you might need in your future career:

Code:
man -k <keyword>       searches all the man-articles for <keyword>
                        and lists the articles where <keyword> was found

Quote:
I know that I should use cmp to tell if the files are the same, but I do not know how to set up the while loop
No problem, we will eventually get to that. You are correct, "cmp" is a correct tool for that purpose.

Why "a correct" and not "the correct"? Because in Unix there are usually several ways to do something - in this case i had "diff" in mind when i asked you, but "cmp" is also correct, so use this. (This - the possibility to do things in several ways - often leads to what Unixers call "religious wars". Some people will be convinced that there is only "one true way" and usually half of them will think variant A as this one true way and the other half will think variant B as the one true way. Exorcism ensues and this is why Unix is said to give people a purpose in life. ;-) )

Quote:
I know I have to use a variable, but how do I get the while loop to transverse the file line by line?
Well, this is easy and i will tell you because it can't be researched easily:

Suppose you have some process, which output is a list, like. You can set up a loop with the elements of the list as variable content using the following construct. It is called a "pipeline":

Code:
process | while read variable ; do
   do_something_with $variable
done

Here is an example. Try out "ls -1" as single command first to see what "goes into" the pipeline, only then try the whole script. It should be pretty self-explanatory:

Code:
#!/bin/ksh

ls -1 | while read filename ; do
     print - "This is file: $filename"
done

Ok, report back when you have all the necessary information and we will continue with the last part of the script.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Editing File using awk/sed

Hello Awk Gurus, Can anyone of you help me with the below problem. I have got a file having data in below format pmFaultyTransportBlocks ----------------------- 9842993 pmFrmNoOfDiscRachFrames ----------------------- NULL pmNoRecRandomAccSuccess -----------------------... (4 Replies)
Discussion started by: Mohammed
4 Replies

2. Shell Programming and Scripting

awk/sed - getting string instead of number

Hi! I am writing a script handling downloading list of files and I have to check whether file is present locally and if not finished than continue downloading. To do so I have to compare sizes of remote file and local file. To check remote file size I have to parse something like this: ... (2 Replies)
Discussion started by: hrwath
2 Replies

3. Shell Programming and Scripting

sed or awk editing help

Hi all I use aix (sadly). I've got a file consisting of fields separated by commas, I need a sed or awk command that will delete all spaces between two commas as long as there are only spaces between the commas. eg ,abc, ,sd , ,dr at would become ,abc,,sd ,,dr at I have... (53 Replies)
Discussion started by: mychmose
53 Replies

4. Shell Programming and Scripting

Line/Variable Editing for Awk sed Cut

Hello, i have a file, i open the file and read the line, i want to get the first item in the csv file and also teh third+6 item and wirte it to a new csv file. only problem is that using echo it takes TOO LONG: please help a newbie. below is my code: WorkingDir=$1 FileName=`cut -d ',' -f... (2 Replies)
Discussion started by: limamichelle
2 Replies

5. Shell Programming and Scripting

match string exactly with awk/sed

Hi all, I have a list that I would like to parse with awk/sed. The list is contains entries such as: JournalTitle: Biochemistry JournalTitle: Biochemistry and cell biology = Biochimie et biologie cellulaire JournalTitle: Biochemistry and experimental biology JournalTitle: Biochemistry and... (6 Replies)
Discussion started by: euval
6 Replies

6. Shell Programming and Scripting

editing file with awk cut and sed

HI All, I am new to unix. I have a file would like to do some editing by using awk, cut and sed. Could anyone help? This file contain 100 lines. There are one line for example: 2,"102343454",5060,"579668","579668","579668","SIP",,,"825922","035885221283026",1,268,"00:59:00.782 APR 17... (2 Replies)
Discussion started by: mimilaw
2 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

sed awk to remove the , in a string

Dear All, Can anyone help to remove the , bewteen "" in a string by using sed or awk? e.g. input : 1,4,5,"abcdef","we,are,here",4,"help hep" output:1,4,5,"abcdef","wearehere",4,"help hep" Thanks, Mimi (5 Replies)
Discussion started by: mimilaw
5 Replies

9. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies
All times are GMT -4. The time now is 07:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy