Sponsored Content
Top Forums Shell Programming and Scripting Dealing with white spaces in bash scripts Post 302781519 by alister on Saturday 16th of March 2013 08:47:41 PM
Old 03-16-2013
Quote:
Originally Posted by venmx
And due to the nature of the find command, I had to expand it into 3 parts ... <snip> ...
Code:
#!/bin/sh

find /dump -type f -gid 200 |
while read i; do
  chgrp `ls -ln "${i}" | awk '{print $3}'` "${i}"
done

find /dump -type d -gid 200 |
while read i; do
  chgrp `ls -lnd "${i}" | awk '{print $3}'` "${i}"
done

find /dump -type l -gid 200 |
while read i; do
  chgrp -h `ls -lnd "${i}" | awk '{print $3}'` "${i}"
done

There's no reason to resort to three different traversals of /dump. Regular files, directories, and softlinks can be visited and modified simultaneously:
Code:
find /dump -gid 200 \( -type f -o -type d -o -type l \) |
while read i; do
  chgrp -h `ls -lnd "${i}" | awk '{print $3}'` "${i}"
done

If you only need to support GNU tools (I'm making the assumption that you're using GNU find), a simpler, more efficient solution presents itself:
Code:
find /dump -gid 200 \( -type f -o -type d -o -type l \) -printf '%U:%p\n' |
while IFS=: read -r uid fname; do
  chgrp -h "$uid" "$i"
done

Regards,
Alister
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

deleting white spaces

How would I delete white spaces in a specified file? Also, I'd like to know what command I would use to take something off a regular expression, and put it onto another. ie. . . . expression1 <take_off> . . . expression2 (put here) . . . Any help would be great, thanks! (10 Replies)
Discussion started by: cary530
10 Replies

2. Shell Programming and Scripting

delete white spaces

hi all... i have the next question: i have a flat file with a lot of records (lines). Each record has 10 fields, which are separated by pipe (|). My problem is what sometimes, in the first record, there are white spaces (no values, nothing) in the beginning of the record, like this: ws ws... (2 Replies)
Discussion started by: DebianJ
2 Replies

3. Shell Programming and Scripting

trimming white spaces

I have a variable that calls in a string from txt file. Problem is the string comes with an abundance of white spaces trailing it. Is there any easy way to trim the tailing white spaces off at the end? Thanks in advance. (9 Replies)
Discussion started by: briskbaby
9 Replies

4. Shell Programming and Scripting

Two or more white spaces in string

Hi, Can anybody suggest me how to combine two strings with two or more white spaces and assign it to a variable? E.g. first=HAI second=HELLO third="$first $second" # appending strings with more than one white spaces echo $third this would print HAI HELLO Output appears... (2 Replies)
Discussion started by: harish_oty
2 Replies

5. Shell Programming and Scripting

Dealing with spaces in file names in a shell script

Hi, What's the best way to find all files under a directory - including ones with space - in order to apply a command to each of them. For instance I want get a list of files under a directory and generate a checksum for each file. Here's the csh script: #!/bin/csh set files = `find $1... (5 Replies)
Discussion started by: same1290
5 Replies

6. Shell Programming and Scripting

white spaces in bash autocompletion

Hello dear community! I've recently written a BASH function for auto completion of options. It works like following: if a user types a command and then an argument to this command which starts with "^-" and then presses TAB, then 'user_command --help (or -h)' is invoked and possible options are... (0 Replies)
Discussion started by: sidorenko
0 Replies

7. Shell Programming and Scripting

Dealing with files with spaces in the name

Hello, I'm a computer science major and I'm having problems dealing with file names with spaces in them. Particularly I'm saving a file name in a variable and then using the variable in a compare function i.e. a='te xt.txt' b='file2.txt' cmp $a $b If anyone could help me with this particular... (10 Replies)
Discussion started by: jakethegreycat
10 Replies

8. Shell Programming and Scripting

Leading white spaces

Hi, I am having problem in deleting the leading spaces:- cat x.csv baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played $ nawk 'BEGIN{FS=","}!a... (2 Replies)
Discussion started by: scripter12
2 Replies

9. Shell Programming and Scripting

Bash - read white spaces

Hello! I have one problem with my bash script - I would like to be able to read white space characters from stdin (for example single " ") - can I acomplish that somehow? I need to read only one character at the time, so I use read -s -n 1 var but it doesn't work for whitespaces apparently. ... (3 Replies)
Discussion started by: xqwzts
3 Replies

10. Shell Programming and Scripting

Dealing with filename spaces in Perl

The following command to replace text in place in multiple files in a directory is tripping up on filename spaces (Windows environment). I really don't know Perl. find '\\server\directory' | xargs perl -pi -e 's/textA/textB/g'Mike (2 Replies)
Discussion started by: Michael Stora
2 Replies
dump(1) 							   User Commands							   dump(1)

NAME
dump - dump selected parts of an object file SYNOPSIS
dump [-aCcfghLorstV [-p]] [ -T index [ , indexn]] filename... dump [ -afhorstL [-p] [v]] filename... dump [ -hsr [-p] [ -d number [ , numbern]]] filename... dump [ -hsrt [-p] [-n name]] filename... DESCRIPTION
The dump utility dumps selected parts of each of its object file arguments. The dump utility is best suited for use in shell scripts, whereas the elfdump(1) command is recommended for more human-readable output. OPTIONS
This utility will accept both object files and archives of object files. It processes each file argument according to one or more of the following options: -a Dumps the archive header of each member of an archive. -c Dumps the string table(s). -C Dumps decoded C++ symbol table names. -f Dumps each file header. -g Dumps the global symbols in the symbol table of an archive. -h Dumps the section headers. -L Dumps dynamic linking information and static shared library information, if available. -o Dumps each program execution header. -r Dumps relocation information. -s Dumps section contents in hexadecimal. -t Dumps symbol table entries. -T index Dumps only the indexed symbol table entry defined by index or a range of entries defined by index1,index2. -T index1,index2 -V Prints version information. The following modifiers are used in conjunction with the options listed above to modify their capabilities. -d number Dumps the section number indicated by number or the range of sections starting at number1 and ending at number2. -d number1,number2 This modifier can be used with -h, -s, and -r. When -d is used with -h or -s, the argument is treated as the number of a section or range of sections. When -d is used with -r, the argument is treated as the number of the section or range of sections to which the relocation applies. For example, to print out all relocation entries associated with the .text section, specify the number of the section as the argument to -d. If .text is section number 2 in the file, dump -r -d 2 will print all associated entries. To print out a specific relocation section, use dump -s -n name for raw data output, or dump -sv -n name for interpreted output. -n name Dumps information pertaining only to the named entity. This modifier can be used with -h, -s, -r, and -t. When -n is used with -h or -s, the argument will be treated as the name of a section. When -n is used with -t or -r, the argument will be treated as the name of a symbol. For example, dump -t -n .text will dump the symbol table entry associated with the symbol whose name is .text, where dump -h -n .text will dump the section header information for the .text section. -p Suppresses printing of the headings. -v Dumps information in symbolic representation rather than numeric. This modifier can be used with -a (date, user id, group id) -f (class, data, type, machine, version, flags) -h (type, flags) -L (value) -o (type, flags) -r (name, type) -s (interpret section contents wherever possible) -t (type, bind) When -v is used with -s, all sections that can be interpreted, such as the string table or symbol table, will be interpreted. For example, dump -sv -n .symtab filename... will produce the same formatted output as dump -tv file- name..., but dump -s -n .symtab filename... will print raw data in hexadecimal. Without additional modifiers, dump -sv filename... will dump all sections in the files, interpreting all those that it can and dumping the rest (such as .text or .data) as raw data. The dump utility attempts to format the information it dumps in a meaningful way, printing certain information in character, hexadecimal, octal, or decimal representation as appropriate. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWbtool | +-----------------------------+-----------------------------+ SEE ALSO
elfdump(1), nm(1), ar.h(3HEAD), a.out(4), attributes(5) SunOS 5.10 6 Sep 2002 dump(1)
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy