Sponsored Content
Top Forums Shell Programming and Scripting Using sed with a foreach loop Post 302279786 by Peggy White on Friday 23rd of January 2009 06:21:30 PM
Old 01-23-2009
Using sed with a foreach loop

So I am back again beating my head against the wall with a shell script and getting a headache! I want to change each year in a file (1980, 1981, 1982, 1983, etc.) to the same year followed by a tab.

The input is "blah blah (1980) blah blah".

I want to get "blah blah (1980 ) blah blah".

Code:
foreach year (1980 1981 1982)
sed -e 's/$year/$year     )/g' input_file > output_file

only changes the last year. Does sed need something special with foreach?

Thanks much to anyone in advance, Peggy

Last edited by bakunin; 01-23-2009 at 08:04 PM.. Reason: added code-tags. Please use them when posting code
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

foreach loop question

Hello, I am new at this forum so please bare with me on this. Within a given directory, I have a list of files in which in each file, I would like to do a substitution. I would like to substitute the string mlcl to mll in each file using the foreach command. I dont quite get how to do that. If... (7 Replies)
Discussion started by: clipski
7 Replies

2. Shell Programming and Scripting

Foreach loop

What am I doing wrong with this foreach loop? foreach var ($argv) @sum = $sum + $var (4 Replies)
Discussion started by: haze21
4 Replies

3. Shell Programming and Scripting

foreach loop

Hi Guys, I have a loop which uses a wildcard i.e. foreach f (*) but when I execute the tcsh file in unix then it gives me an error ->>>>>>>foreach: words not parenthesized<<<<<<<<<<- Any help. (1 Reply)
Discussion started by: abch624
1 Replies

4. Shell Programming and Scripting

foreach loop + 2 variables

In a foreach loop, is it possible for the loop to go through 2 arguments instead of one i.e. instead of foreach i (do stuff for i), we have foreach i j(do stuff for i; do stuff for j) I am working under BASH and TCSH shell environments cheers (3 Replies)
Discussion started by: JamesGoh
3 Replies

5. Shell Programming and Scripting

foreach loop

Hi everyone Does anyone know what is wrong with this script. i keep getting errors foreach filename (`cat testing1`) set string=$filename set depth=`echo "$string" echo $depth end the error is the following testing: line 1: syntax error near unexpected token `(' testing: line 1:... (3 Replies)
Discussion started by: ROOZ
3 Replies

6. UNIX for Advanced & Expert Users

Problem with foreach loop

Hi All, Is there any problem with the below 'foreach' loop? foreach risk_factor ($(cat "$rf_list")) where "rf_list=$SCRIPT/Utility/rflist.txt " I'm wondering, it is throwing below error message: syntax error at line 34: `(' unexpected Any idea/suggestions ? Thanks in advance /... (7 Replies)
Discussion started by: ganapati
7 Replies

7. UNIX for Dummies Questions & Answers

Using the Foreach loop, Needing help

I am trying to make a script for my Counter-Strike: Source servers. What i am wanting it to do is for it to restart each server, the only way i can think of doing this in through for each. Years what i have at the moment. server_start() { START=`ps x | grep SCREEN | grep $SRV | cut -d '?' -f... (5 Replies)
Discussion started by: grahamn95
5 Replies

8. Shell Programming and Scripting

foreach loop problem

Dear all, I wrote a script to download files and move files in directories according to their name. Now here is the problem: Both p101 and p360 data download successfully, but when I move them according to the year and month, only p101 data can be placed at the right location, p360,... (1 Reply)
Discussion started by: handsonzhao
1 Replies

9. UNIX for Dummies Questions & Answers

foreach loop in csh

Hi everyone I'm new to unix and encountered a small problem i couldnt find out a reason why it doesn't work..please help.. in my csh script when i tried to use the foreach loop like this: foreach x ( ls ) echo $x end when i tried to run it, it printed out 'ls' to the std out instead of... (3 Replies)
Discussion started by: ymc1g11
3 Replies

10. Shell Programming and Scripting

Foreach loop with two variables

I need to put together a script that will take the contents of two different files (database name and database owner) and put them in two variables within a line: foreach x (`cat /local/hd3/dba/tools/build_db_scripts/dbs`) foreach z (`cat /local/hd3/dba/tools/build_db_scripts/dbas`)... (6 Replies)
Discussion started by: deneuve01
6 Replies
CSS::DOM::Rule(3pm)					User Contributed Perl Documentation				       CSS::DOM::Rule(3pm)

NAME
CSS::DOM::Rule - CSS rule class for CSS::DOM VERSION
Version 0.14 SYNOPSIS
use CSS::DOM::Rule ':all'; # import constants use CSS::DOM; $sheet = new CSS::DOM; $sheet->insertRule('bla blah blah {}'); $rule = $sheet->cssRules->[0]; $rule->type; # STYLE_RULE $rule->cssText; # 'bla blah blah {}' or similar $rule->cssText('p { margin: 0 }'); # replace it $rule->parentStyleSheet; # $sheet DESCRIPTION
This module provides the CSS rule class for CSS::DOM. It implements the CSSRule and CSSUnknownRule DOM interfaces. METHODS
Constructor Only call the constructor on this class to create an 'unknown' rule. You have to call the constructor on a particular subclass to get another type. Normally you do not need to call this directly anyway. (See CSS::DOM's "parse" and "insertRule" methods.) But just in case you do want to call it, here it is: new CSS::DOM::Rule $parent; # unknown rule require CSS::DOM::Rule::Style new CSS::DOM::Rule::Style $parent; # etc. $parent is the parent rule, if the rule is nested, or the parent style sheet otherwise. Object Methods type Returns one of the constants below indicating the type of rule. cssText Returns this rule's CSS code. If you pass an argument, it will be parsed as the new CSS code for this rule (replacing the existing data), and the old value will be returned. This method will die if the replacement CSS code creates a different type of rule. parentStyleSheet This returns the style sheet to which the rule belongs. parentRule This returns the rule's parent rule, if there is one, or an empty list otherwise. There is only a parent rule if this one is nested, e.g., inside a media rule. EXPORTS
The following constants that indicate the type of rule will be exported on request (individually or with the ':all' tag): UNKNOWN_RULE STYLE_RULE CHARSET_RULE IMPORT_RULE MEDIA_RULE FONT_FACE_RULE PAGE_RULE SEE ALSO
CSS::DOM CSS::DOM::Rule::Style CSS::DOM::Rule::Media CSS::DOM::Rule::Page CSS::DOM::Rule::Import perl v5.10.1 2010-12-10 CSS::DOM::Rule(3pm)
All times are GMT -4. The time now is 09:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy