perform actions at specific locations in data frame


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perform actions at specific locations in data frame
# 1  
Old 02-29-2012
perform actions at specific locations in data frame

Hi everyone,

I got a data frame like the one below and and would like to do the following:

Ignore the first 3 rows and check in all following rows the second position. If the value is >500, subtract 100.


Example DF:
Code:
ABC    22    DE    12    
BCD    223    GH    12
EFG    2104    DH    25
ghF    3452    TH    35
sft    512    as    10


How it should look like:
Code:
ABC    22    DE    12    
BCD    223    GH    12
EFG    2104    DH    25
ghF    3352    TH    35
sft    112    as    10


Any idea how this could be done with sed/awk?

many thanks for your help!

Last edited by Scott; 02-29-2012 at 11:11 AM.. Reason: Added code tags
# 2  
Old 02-29-2012
Try:
Code:
awk 'NR>3 && $2 > 500{$2-=100}1' file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 02-29-2012
Thanks a lot - exactly what I was looking for:-)

---------- Post updated at 05:22 PM ---------- Previous update was at 04:28 PM ----------

sorry, I just realized that like this the columns are now space separated (should stay tab-delimited). How could this be done?

many thanks again
# 4  
Old 02-29-2012
Code:
awk 'NR>3 && $2>500{$2-=100}1' OFS="\t" file

This User Gave Thanks to ctsgnb For This Post:
# 5  
Old 02-29-2012
thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to delete empty files from specific locations

Hi, I need help in regard to developing a shell script to delete empty files from multiple specific locations. The directory paths will be stored in a text file. So the requirement is to read the text file for one specific path and then remove empty files from that particular path. Looping through... (4 Replies)
Discussion started by: Khan28
4 Replies

2. Shell Programming and Scripting

awk : collecting all data between two time frame

Hi Experts , I need your help to collect the complete data between two time frame from the log files, when I try awk it's collecting the data only which is printed with time stamp for example, awk works well from "16:00 to 17:30" but its not collecting <line*> "from 17:30 to 18:00" ... (8 Replies)
Discussion started by: zenkarthi
8 Replies

3. Shell Programming and Scripting

Problem in Pattern-Specific Actions in awk

Hi i am in learning phase of unix i am able to understand basic of awk but not able to understand Pattern-Specific Actions in awk below is the snippet . awk ' / *\$*\. */ { print $1,$2,$3,"*"; } / *\$0\. */ { print ; } ' fruit_prices.txthere i am not getting the use of wild card. what... (4 Replies)
Discussion started by: scriptor
4 Replies

4. Shell Programming and Scripting

Removing repeating lines from a data frame (AWK)

Hey Guys! I have written a code which combines lots of files into one big file(.csv). However, each of the original files had headers on the first line, and now that I've combined the files the headers are interspersed throughout the new combined data frame. For example, throughout the data... (21 Replies)
Discussion started by: gd9629
21 Replies

5. Shell Programming and Scripting

perform some operation on a specific coulmn starting from a specific line

I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. eg: 50.000000 1 1 1 1000.00000 1000.00000 50000.000 19 19 3.69797533E-07 871.66394 ... (3 Replies)
Discussion started by: shashi792
3 Replies

6. Shell Programming and Scripting

Perform a set of actions for a specific file type

Hello, I have a problem that I'm having quite a bit of trouble with. I am trying to create a script that performs a specific sequence of actions for a file of a specific type. This is an abbreviated version of my basic script: #!/bin/sh #coulombic calculations... (2 Replies)
Discussion started by: oehtus
2 Replies

7. Shell Programming and Scripting

search string during a specific time frame

Can someone please help me with searching a string during a specific time frame. Below is the format of the time from my log file. "GET /AAM2009_wherewereheaded.wmv HTTP/1.1" 200 52307085 The search string I need is "AAM2009_wherewereheaded.wmv" I need to search the number of... (1 Reply)
Discussion started by: tadi18
1 Replies

8. Programming

Printing Dots in specific Locations in the Console ?

Point.h #pragma once #include <iostream> using namespace std; class Point { private: int x; int y; public: Point(void); Point( int x, int y ); Point( const Point &xPoint ); ~Point(void); (0 Replies)
Discussion started by: Max_Payne
0 Replies

9. AIX

Script to perform some actions on multiple files

I have this Korn script that I wrote (with some help) that is run by cron. I basically watches a file system for a specific filename to be uploaded (via FTP), checks to make sure that the file is no longer being uploaded (by checking the files size), then runs a series of other scripts. The... (2 Replies)
Discussion started by: heprox
2 Replies
Login or Register to Ask a Question