Sponsored Content
Top Forums UNIX for Dummies Questions & Answers grep for a backslash as for loop parameter Post 302538010 by idlechatter on Monday 11th of July 2011 12:37:14 PM
Old 07-11-2011
I'm trying to read the /usr/dt/config/C/Xresources file, specifically, the greeting.

The file looks like this
Code:
!!#########################################################
!!
!!     Xresources
!!
!!     Configuration file for the Login Manager
!!
...
...
Dtlogin*greeting.labelString:     Hello! You are on %LocalHost% \n\n \
This computer is being monitored for all purposes. You will be responsible for \n \
all actions taken while logged in to this computer. Please make sure to \n \
Log out when you are finished with your session \n \
Have fun! \n
!! Dtlogin*greeting.persLabelString:   Welcome %s
!! Dtlogin*greeting.alignmnet:             ALIGNMENT_CENTER
!! ########################################################
!!
!! Size of Text Input Area

I just want to print out the "Dtlogin*greeting.labelString: " line and what it is set to.

So the output would be:
Code:
Dtlogin*greeting.labelString:     Hello! You are on %LocalHost% \n\n \
This computer is being monitored for all purposes. You will be responsible for \n \
all actions taken while logged in to this computer. Please make sure to \n \
Log out when you are finished with your session \n \
Have fun! \n

I did find a workaround to that code i posted above. Instead of doing the grep inside the for loop, you grep and redirect output to a file, and loop over that file.

Here is the workaround:
Code:
file=/etc/dt/config/C/Xresources
tempfile=tmpfile.txt
keyword="Dtlogin\*greeting\.labelString:"
cat $file | /usr/xpg4/bin/grep -e "$keyword" -e \\\\ > $tempfile

for line in `cat $tempfile`; do
     echo $line
done

rm $tempfile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How ro handle backslash character in grep?

Hi , I am doing invert grep using -v but the string contain "/" which break the grep command and it do not skip the lines with "/" on it. Diffu.txt ======== 1159c1159 < <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton7466"> --- > <td... (1 Reply)
Discussion started by: rajbal
1 Replies

2. UNIX for Advanced & Expert Users

How to handle backslash in grep string

Hi , I am doing invert grep using -v but the string contain "/" which break the grep command and it do not skip the lines with "/" on it. Diffu.txt ======== 1159c1159 < <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton7466"> --- > <td... (6 Replies)
Discussion started by: rajbal
6 Replies

3. Shell Programming and Scripting

Using the counter of a for loop in command line parameter

Say I have (in psuedocode) For i=1 to 10 tar cvfb /... 5*i /junk(i) end What I mean is that I want each successive for loop to have the block size parameter be 5 times the current counter. This isn't my actual code, just a stupid example...So the question is how do I descrive that parameter... (2 Replies)
Discussion started by: jeriryan87
2 Replies

4. Shell Programming and Scripting

Problem if parameter has space in it using loop

for cmdopts in $*;do case $cmdopts in -mode) mode="$2";shift 2 ;; -server) server="$2";shift 2 ;; -Id) Id="$2";shift 2 ;; -passwd) passwd="$2";shift 2 ;; -rmtDir) rmtDir="$2";shift 2 ;; -lcDir) ... (9 Replies)
Discussion started by: pinnacle
9 Replies

5. UNIX for Dummies Questions & Answers

Substituiton for grep paragraph parameter

My bash doesn't have grep -p.. I often find myself wanting to search a section of a man page for areas dealing with a specific property or parameter... For instance wanting to read everything in the man pages for bash that deal with Parameter Expansion.. Is there a way to do this with grep if... (3 Replies)
Discussion started by: glev2005
3 Replies

6. UNIX for Advanced & Expert Users

grep for a backslash question

Why does this work when grepping for a backslash? grep '\\' .bash_history grep "" .bash_historyWhy does this not work when grepping for a backslash? grep "\\" .bash_historyI know this works works but just don't understand why I need 4 backslashes when using double quotes. grep "\\\\"... (7 Replies)
Discussion started by: cokedude
7 Replies

7. Shell Programming and Scripting

Attempting to pass my array as a nested parameter to loop. A little lost.

I want to pass this array as a parameter. IFS=$'\n' fortune_lines=($(fortune | fold -w 30 )) Inside of this line screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say ${fortune_lines}\r"`" And I am lost at this point. I am thinking something like this? Then make it loop.. ... (7 Replies)
Discussion started by: briandanielz
7 Replies

8. Shell Programming and Scripting

Loop over awk or passing parameter

I wrote this script which works well when I manually input 55518622 and 1 but I need this script to be generic and loop over the following table awk '$4>(55518622-500000) && $4<(55518622+500000)' chr1_GEN2bim | awk 'BEGIN {min=1000000000; max=0;}; {\ if($4<min && $4 != "") min = $4; if($4>max... (8 Replies)
Discussion started by: fat
8 Replies

9. UNIX for Dummies Questions & Answers

Help on for loop with a parameter

Hi, need help to pass an paremeter to for loop script $cat tp.ksh for i in `grep $1 | cut -d "/" -f 5 | cut -d" " -f2` do fgrep $i $1 | grep 'with value' | cut -d "|" -f 2 done $tp.ksh test_data.plan_49989_2015-05-01-00-13-38.log command doesnot return the values. (5 Replies)
Discussion started by: AAHinka
5 Replies

10. Shell Programming and Scripting

How to pass function parameter to do loop?

Hi All, I have created one function for KSH and was running well with one parameter input since I just had to use $1 to get the parameter. Now I want to do loop for each parameter(actually filenames) . I have try to use do loop, but $i does not resolve to parameter instead it resolves to 1,... (5 Replies)
Discussion started by: mysocks
5 Replies
APROPOS(1)						    BSD General Commands Manual 						APROPOS(1)

NAME
apropos, whatis -- keyword search whatis documentation databases SYNOPSIS
apropos [-d] keyword ... whatis [-d] keyword ... DESCRIPTION
The apropos utility searches a set of databases looking for documentation matching each keyword and displays the results. The whatis utility does the same search but only on complete words. -d Print extra debugging information. The keyword is simply passed to grep(1) allowing for extended regular expression matches. ENVIRONMENT
The following environment variables affect the execution of apropos: MANLOCALES, MANPATH, PATH Used to find the location of the whatis database files. See manpath(1) for additional information. PAGER Program used to display files. If unset, more -s is used. DIAGNOSTICS
The apropos utility exits 0 if a keyword matched and 1 if no keywords are matched or no whatis databases are found. SEE ALSO
grep(1), makewhatis(1), man(1), manpath(1), man.conf(5) BSD
September 1, 2010 BSD
All times are GMT -4. The time now is 09:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy