Sponsored Content
Top Forums Shell Programming and Scripting Sed Question 1. (Don't quite know how to use sed! Thanks) Post 302257277 by beibeiatNY on Tuesday 11th of November 2008 11:02:08 PM
Old 11-12-2008
Sed Question 1. (Don't quite know how to use sed! Thanks)

  1. Write a sed script to extract the year, rank, and stock for the most recent 10 years available in the file top10_mktval.csv, and output in the following format:



------------------------------
YEAR |RANK| STOCK
------------------------------
2007 | 1 | Exxon Mobil
2007 | 2 | Genl Electric
2007 | 3 | Microsoft Corp
2007 | 4 | AT&T Inc
2007 | 5 | Procter & Gamble
2007 | 6 | Google Inc'A'
2007 | 7 | Chevron Corp
2007 | 8 | Johnson & Johnson
2007 | 9 | Wal-Mart Stores
2007 | 10 | Bank of America
2006 | 1 | Exxon Mobil
...



Observe that:

  • Headers are added.
  • Rank is now the second field.
  • The last two fields in the original file are not printed.
  • The delimiters '|' are aligned.
You may assume that the records in this file are always in reverse chronological order, and there are always 10 entries (ranked 1-10) for each year.

top10_mktval.csv is in the attachment


Thank you !

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sed question

My data file look like tis field1:field2:field3:field4:field5 I wan to compare field 2 with 1 variable and if match change the details of it. How can i do it? I used to do it like tis: #in shell script checkSerial() { while do echo "  \c" ... (1 Reply)
Discussion started by: AkumaTay
1 Replies

2. UNIX for Dummies Questions & Answers

sed question

Hi, i'm in vi and am trying to globbaly changing some values. msisdn="4478....... for msisdn="078...... i've tried :s/msisdn="4478/msisdn="078/g but it complains it can't match the string. I'm thinking its the = and " thats the problem. Please help. HPUX 11i Cheers (3 Replies)
Discussion started by: nhatch
3 Replies

3. Shell Programming and Scripting

sed question

all, I am trying to use sed to read into a file and if a certain line exists (TRUSTHOSTKEY = YES), then I want to replace it with TRUSTHOSKEY = NO. My problem is that the line may exist as: trusthostkey=yes trusthostkey = yes TRUSTHOSTKEY = YES trusthostkey =yes It will however always... (1 Reply)
Discussion started by: hedrict
1 Replies

4. Shell Programming and Scripting

sed question

I'm wondering if you can do the following with sed or some other way. I would like to chang the character "*" in a string to "\052" inside of a script? i.e. string="text * text" #chang to string="text \052 text" (2 Replies)
Discussion started by: OldNo7
2 Replies

5. Shell Programming and Scripting

Use variable in sed don't work.

Hi all. I have a script as below: cutmth=`TZ=CST+2160 date +%b` export cutmth echo $cutmth >> date.log sed -n "/$cutmth/$p" alert_sbdev1.log > alert_summ.log My purpose is to run through the alert_sbdev1.log and find the 1st occurence of 'Jan' and send everything after that line to... (4 Replies)
Discussion started by: ahSher
4 Replies

6. Shell Programming and Scripting

Question on SED

Say for example I have a string as "/diggi/binary/d/e/f" I need the output as e ( The Second last “string”) . I want this using SED. Because using AWK its very easy. (4 Replies)
Discussion started by: Shell_Learner
4 Replies

7. Shell Programming and Scripting

grep? awk? sed? I don't know

Hi everyone! I have a file like this And I would like to find the Medium label when the value "last write" is "Jan 14" (it's could be another value like "jan 6") I really don't know what way to use to solve this problem... Thanks! (5 Replies)
Discussion started by: Castelior
5 Replies

8. UNIX for Dummies Questions & Answers

Using sed to change lines and add them if they don't exist..

I've googled the hell out of this, and in my quest to advance my knowledge and expertise in modifying phones to make them more awesome, I ended up here. I've found answers about patterns and whatnot that seem really complex for what I am trying to do, and basically it is this: if the line says... (2 Replies)
Discussion started by: Silentbtdeadly
2 Replies

9. UNIX for Beginners Questions & Answers

sed question

have some data and I'm attempting to manipulate with sed with not much success. Name John Davis Phone 5555555 Name Tim Watson Phone 1111111 would like to get that data to sort like this John Davis 5555555 Tim Watson 1111111 gotten sed to search for the value below 'Name'... (5 Replies)
Discussion started by: jimmyf
5 Replies
mdbFontset(5)							 The m17n Library						     mdbFontset(5)

NAME
mdbFontset - Fontset DESCRIPTION
The m17n library loads a fontset definition from the m17n database by the tags <fontset, FONTSET-NAME>. The plist format of the data is as follows: FONTSET ::= PER-SCRIPT * PER-CHARSET * FALLBACK * PER-SCRIPT ::= '(' SCRIPT PER-LANGUAGE + ')' PER-LANGUAGE ::= '(' LANGUAGE FONT-SPEC-ELEMENT + ')' PER-CHARSET ::= '(' CHARSET FONT-SPEC-ELEMENT + ')' FALLBACK ::= FONT-SPEC-ELEMENT FONT-SPEC-ELEMENT ::= '(' FONT-SPEC [ FLT-NAME ] ')' FONT-SPEC ::= '(' [ FOUNDRY FAMILY [ WEIGHT [ STYLE [ STRETCH [ ADSTYLE ]]]]] REGISTRY [ OTF-SPEC ] [ LANG-SPEC ] ')' SCRIPT is a symbol of script name (e.g. latin, han) or nil. LANGUAGE is a two-letter symbol of language name code defined by ISO 639 (e.g. ja, zh) or nil. FONT-SPEC is to specify properties of a font. FOUNDRY to REGISTRY are symbols corresponding to Mfoundry to Mregistry property of a font. See m17nFont for the meaning of each property. OTF-SPEC is a symbol specifyng the required OTF features. The symbol name has the following syntax. OTF-SPEC-NAME ::= ':otf=' SCRIPT LANGSYS ? GSUB-FEATURES ? GPOS-FEATURES ? SCRIPT ::= SYMBOL LANGSYS ::= '/' SYMBOL GSUB-FEATURES ::= '=' FEATURE-LIST ? GPOS-FEATURES ::= '+' FEATURE-LIST ? FEATURE-LIST ::= '~' ? FEATURE ( ',' '~' ? FEATURE ',' ) Here, FEATURE is a four-letter Open Type feature. LANG-SPEC is a symbol specifying the required language support. The symbol name has the following syntax. LANG-SPEC-NAME ::= ':lang=' LANG Here, LANG is a two or three-letter ISO-639 language code. FLT-NAME is a name of Font Layout Table (Font Layout Table). EXAMPLE
This is an example of PER_SCRIPT. (han (ja ((jisx0208.1983-0))) (zh ((gb2312.1980-0))) (nil ((big5-0)))) It instructs the font selector to use a font of registry 'jisx0208.1983-0' for a 'han' character (i.e. a character whose Mscript property is 'han') if the character has Mlanguage text property 'ja' in an M-text and the character is in the repertories of such fonts. Otherwise, try a font of registry 'gb2312.1980-0' or 'big5-0'. If that 'han' character does not have Mlanguage text property, try all three fonts. See the function mdraw_text() for the detail of how a font is selected. COPYRIGHT
Copyright (C) 2001 Information-technology Promotion Agency (IPA) Copyright (C) 2001-2011 National Institute of Advanced Industrial Science and Technology (AIST) Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License <http://www.gnu.org/licenses/fdl.html>. Version 1.6.2 12 Jan 2011 mdbFontset(5)
All times are GMT -4. The time now is 04:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy