Search : in
By :

Shell, Grep and Sed

Last answer on Aug 13, 2009 7:13:54 am BST Bugz, on Dec 1, 2008 10:51:58 am GMT 
 Report this message to moderators

Hello, I need help. I have to sort information from a file and place into excel
I no that I have use a shell with the cmds 'grep' and 'sed' but unsure how to go about it

The file looks like this:

26/10/01 686856 70.00
26/10/01 STANDING ORDER 1301.25
27/10/01 686849 580.00
28/10/01 653937 21.00
29/10/01 653938 20.00
29/10/01 686855 76.72
29/10/01 DIRECT DEBIT 10.00
29/10/01 DIRECT DEBIT 44.00
29/10/01 STANDING ORDER 23.00


I have to sort it in to 3 columns
Date, description and money

Any help would be great thx

Configuration: Windows XP
Internet Explorer 7.0

Best answers for « Shell, Grep and Sed » in :
Displaying a file without Commentary lines Show Displaying a file without Commentary lines Grep Sed Perl It may be needed to view a file without displaying the numerous commentary lines attached to it (especially for the configuration files of your OS) and also considering...
[Shell] Retrieving your public IP Show [Shell] Retrieving your public IP Implementation GET Lynx Sed For several reasons, we may need to recover its public IP address in a script. The problem that arises when you are on a LAN, is to find the IP without human...
Linux - The shell Show Introduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...
[Sed] Delete one or more lines from a file Show[Sed] Delete one or more lines from a file Removing one (or several) line (s) of a file Syntax: sed '{[/]||[/]}d' sed '{[/][,][/]d' /.../=delimiters n = line number...
Recursive GREP ShowRecursive GREP It may happen that the option –r (or –d recurse) of the command grep is not accessible; you are therefore requested to use the command find. An example, when searching for “kioskea” in all files constantly from...
[Shell]Create a file having a specific size ShowShell]Create a file having a specific size The dd command allows you to create "empty" file of desired size, creating these arbitrary heavy files, may be useful for testing purposes. Use command below: dd if=/dev/zero of=file_to...
Download SSH Secure Shell ShowSSH secure shell for workstations is a flexible client SSH allowing to connect in a secured way to remote applications. http://www.commentcamarche.net/faq/images/NHc6wz5jOYBhPXTis.png
UNIX system - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence its name "shell". The shell therefore acts as an intermediary between the operating system and the user using command lines...
Using FTP commands ShowThe FTP protocol FTP (File Transfer Protocol) is a protocol — meaning a standard language that lets two machines communicate — used so that computers of different types (or with different operating systems) can transfer files over a...
Environment variables ShowEnvironment variables An environment variable is a dynamic value loaded into the memory that can be used by several processes operating simultaneously. On most operating systems, the location of some libraries or of the main system executables may...

1

Sacabouffe, on Dec 1, 2008 9:44:05 pm GMT

Hi
Mmm... These strings are rather annoying because they correspond to 2 columns in fact.
The only idea I have (surely not the best) is first to replace the strings composed by 2 words and a space by only one full string.
Are STANDING ORDER and DIRECT DEBIT the only kind of strings you have ?
If it's the case, what I suggest is (suppose your file is called data.txt) :

sed 's/G O/G_O/g' data.txt > data_mod.txt
sed 's/T D/T_D/g' data_mod.txt > data.txt
rm data_mod.txt
Then you really have 3 columns and you can extract them with awk for example, it is :
cat data.txt | awk -F " " '{print $1}' > column1.txt
cat data.txt | awk -F " " '{print $2}' > column2.txt
cat data.txt | awk -F " " '{print $3}' > column3.txt
At last, you can modify the second file column2.txt to have the second column like it was :
sed 's/G_O/G O/g' column2.txt > column2_mod.txt
sed 's/T D/T_D/g' column2_mod.txt > column2.txt
rm column2_mod.txt
Is it more or less what you wanted to do ?
See you ! You'd better close your eyes, bow your head
And wait for the ricochet

Reply to Sacabouffe

2

jipicy, on Dec 4, 2008 5:04:55 pm GMT

Hi,

[tmpfs]$ cat file.txt
26/10/01 686856 70.00
26/10/01 STANDING ORDER 1301.25
27/10/01 686849 580.00
28/10/01 653937 21.00
29/10/01 653938 20.00
29/10/01 686855 76.72
29/10/01 DIRECT DEBIT 10.00
29/10/01 DIRECT DEBIT 44.00
29/10/01 STANDING ORDER 23.00

[tmpfs]$ sed 's/ /,/1;s/\(.*\) \(.*\)/\1,\2/' file.txt
26/10/01,686856,70.00
26/10/01,STANDING ORDER,1301.25
27/10/01,686849,580.00
28/10/01,653937,21.00
29/10/01,653938,20.00
29/10/01,686855,76.72
29/10/01,DIRECT DEBIT,10.00
29/10/01,DIRECT DEBIT,44.00
29/10/01,STANDING ORDER,23.00

[tmpfs]$ 
;-))
$ man woman
Il n'y a pas de page de manuel pour woman.

Reply to jipicy

3

 Sacabouffe, on Dec 5, 2008 5:08:47 pm GMT

Hi

sed 's/ /,/1;s/\(.*\) \(.*\)/\1,\2/' file.txt
O_o
I'll try to understand... one of these days... :-DDD

See you ;-) You'd better close your eyes, bow your head
And wait for the ricochet

Reply to Sacabouffe