Sponsored Content
Top Forums Shell Programming and Scripting add increment field when first field changes Post 89578 by azekry on Monday 14th of November 2005 12:01:54 PM
Old 11-14-2005
add increment field when first field changes

Hi
I have a file that looks like the following:

Name1 aaa bbbb
Name1 ffd hhghg
Name1 dffg ghhhh
Name2 rtrt dfff
Name2 rrtfr tgtt
Name2 dsddf gfggf
Name2 ffffg gfgf
NAme3 fdff ghhgh

Is it possible to format it so that a number increment field is added whenever the first field in a record changes. like that

1 Name1 aaa bbbb
1 Name1 ffd hhghg
1 Name1 dffg ghhhh
2 Name2 rtrt dfff
2 Name2 rrtfr tgtt
2 Name2 dsddf gfggf
2 Name2 ffffg gfgf

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reindex or re-increment last field of txt file.

I am using a database text file with a field that increments +1 with each new entry, occasionally if a entry is deleted the unique sequence is disrupted. I am looking for a small script/function in sh and/or perl that would re index this. Example of db file: Name | Address | misc |number... (2 Replies)
Discussion started by: silenthands
2 Replies

2. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

3. Shell Programming and Scripting

awk field equal something, then add something to the field

Hi Everyone, a.txt a b c 1 e e e e e a b c 2 e e e e e the output is a b c 1 e e e e e a 00b c 2 e e e e e when 4th field = '2', then add '00' in the front of 2nd field value. Thanks (9 Replies)
Discussion started by: jimmy_y
9 Replies

4. Shell Programming and Scripting

Add field delimiter for the last field

I have a file with three fields and field delimiter '|' like: abc|12:13:45|123 xyz|12:87:32| qwe|54:21:09 In the file the 1st line has proper data -> abc|12:13:45|123 ,the 2nd line doesnt has data for the 3rd field which is okay , the 3rd line doesnt has data for the 3rd field as well the... (5 Replies)
Discussion started by: mehimadri
5 Replies

5. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

6. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

7. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

8. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

9. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

10. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies
filename(3erl)						     Erlang Module Definition						    filename(3erl)

NAME
filename - Filename Manipulation Functions DESCRIPTION
The module filename provides a number of useful functions for analyzing and manipulating file names. These functions are designed so that the Erlang code can work on many different platforms with different formats for file names. With file name is meant all strings that can be used to denote a file. They can be short relative names like foo.erl , very long absolute name which include a drive designator and direc- tory names like D:usr/localinerl/lib oolsfoo.erl , or any variations in between. In Windows, all functions return file names with forward slashes only, even if the arguments contain back slashes. Use join/1 to normalize a file name by removing redundant directory separators. The module supports raw file names in the way that if a binary is present, or the file name cannot be interpreted according to the return value of file:native_name_encoding/0 , a raw file name will also be returned. For example filename:join/1 provided with a path component being a binary (and also not being possible to interpret under the current native file name encoding) will result in a raw file name being returned (the join operation will have been performed of course). For more information about raw file names, see the file module. DATA TYPES
name() = string() | atom() | DeepList | RawFilename DeepList = [char() | atom() | DeepList] RawFilename = binary() If VM is in unicode filename mode, string() and char() are allowed to be > 255. RawFilename is a filename not subject to Unicode translation, meaning that it can contain characters not conforming to the Unicode encoding expected from the filesystem (i.e. non-UTF-8 characters although the VM is started in Unicode filename mode). EXPORTS
absname(Filename) -> string() Types Filename = name() Converts a relative Filename and returns an absolute name. No attempt is made to create the shortest absolute name, because this can give incorrect results on file systems which allow links. Unix examples: 1> pwd(). "/usr/local" 2> filename:absname("foo"). "/usr/local/foo" 3> filename:absname("../x"). "/usr/local/../x" 4> filename:absname("/"). "/" Windows examples: 1> pwd(). "D:/usr/local" 2> filename:absname("foo"). "D:/usr/local/foo" 3> filename:absname("../x"). "D:/usr/local/../x" 4> filename:absname("/"). "D:/" absname(Filename, Dir) -> string() Types Filename = name() Dir = string() This function works like absname/1 , except that the directory to which the file name should be made relative is given explicitly in the Dir argument. absname_join(Dir, Filename) -> string() Types Dir = string() Filename = name() Joins an absolute directory with a relative filename. Similar to join/2 , but on platforms with tight restrictions on raw filename length and no support for symbolic links (read: VxWorks), leading parent directory components in Filename are matched against trail- ing directory components in Dir so they can be removed from the result - minimizing its length. basename(Filename) -> string() Types Filename = name() Returns the last component of Filename , or Filename itself if it does not contain any directory separators. 5> filename:basename("foo"). "foo" 6> filename:basename("/usr/foo"). "foo" 7> filename:basename("/"). [] basename(Filename, Ext) -> string() Types Filename = Ext = name() Returns the last component of Filename with the extension Ext stripped. This function should be used to remove a specific extension which might, or might not, be there. Use rootname(basename(Filename)) to remove an extension that exists, but you are not sure which one it is. 8> filename:basename("~/src/kalle.erl", ".erl"). "kalle" 9> filename:basename("~/src/kalle.beam", ".erl"). "kalle.beam" 10> filename:basename("~/src/kalle.old.erl", ".erl"). "kalle.old" 11> filename:rootname(filename:basename("~/src/kalle.erl")). "kalle" 12> filename:rootname(filename:basename("~/src/kalle.beam")). "kalle" dirname(Filename) -> string() Types Filename = name() Returns the directory part of Filename . 13> filename:dirname("/usr/src/kalle.erl"). "/usr/src" 14> filename:dirname("kalle.erl"). "." 5> filename:dirname("\usr\src/kalle.erl"). % Windows "/usr/src" extension(Filename) -> string() Types Filename = name() Returns the file extension of Filename , including the period. Returns an empty string if there is no extension. 15> filename:extension("foo.erl"). ".erl" 16> filename:extension("beam.src/kalle"). [] flatten(Filename) -> string() Types Filename = name() Converts a possibly deep list filename consisting of characters and atoms into the corresponding flat string filename. join(Components) -> string() Types Components = [string()] Joins a list of file name Components with directory separators. If one of the elements of Components includes an absolute path, for example "/xxx" , the preceding elements, if any, are removed from the result. The result is "normalized": * Redundant directory separators are removed. * In Windows, all directory separators are forward slashes and the drive letter is in lower case. 17> filename:join(["/usr", "local", "bin"]). "/usr/local/bin" 18> filename:join(["a/b///c/"]). "a/b/c" 6> filename:join(["B:a\b///c/"]). % Windows "b:a/b/c" join(Name1, Name2) -> string() Types Name1 = Name2 = string() Joins two file name components with directory separators. Equivalent to join([Name1, Name2]) . nativename(Path) -> string() Types Path = string() Converts Path to a form accepted by the command shell and native applications on the current platform. On Windows, forward slashes is converted to backward slashes. On all platforms, the name is normalized as done by join/1 . 19> filename:nativename("/usr/local/bin/"). % Unix "/usr/local/bin" 7> filename:nativename("/usr/local/bin/"). % Windows "\usr\local\bin" pathtype(Path) -> absolute | relative | volumerelative Returns the type of path, one of absolute , relative , or volumerelative . absolute : The path name refers to a specific file on a specific volume. Unix example: /usr/local/bin Windows example: D:/usr/local/bin relative : The path name is relative to the current working directory on the current volume. Example: foo/bar, ../src volumerelative : The path name is relative to the current working directory on a specified volume, or it is a specific file on the current work- ing volume. Windows example: D:bar.erl, /bar/foo.erl rootname(Filename) -> string() rootname(Filename, Ext) -> string() Types Filename = Ext = name() Remove a filename extension. rootname/2 works as rootname/1 , except that the extension is removed only if it is Ext . 20> filename:rootname("/beam.src/kalle"). /beam.src/kalle" 21> filename:rootname("/beam.src/foo.erl"). "/beam.src/foo" 22> filename:rootname("/beam.src/foo.erl", ".erl"). "/beam.src/foo" 23> filename:rootname("/beam.src/foo.beam", ".erl"). "/beam.src/foo.beam" split(Filename) -> Components Types Filename = name() Components = [string()] Returns a list whose elements are the path components of Filename . 24> filename:split("/usr/local/bin"). ["/","usr","local","bin"] 25> filename:split("foo/bar"). ["foo","bar"] 26> filename:split("a:\msdev\include"). ["a:/","msdev","include"] find_src(Beam) -> {SourceFile, Options} | {error,{ErrorReason,Module}} find_src(Beam, Rules) -> {SourceFile, Options} | {error,{ErrorReason,Module}} Types Beam = Module | Filename Module = atom() Filename = string() | atom() SourceFile = string() Options = [Opt] Opt = {i, string()} | {outdir, string()} | {d, atom()} ErrorReason = non_existing | preloaded | interpreted Finds the source filename and compiler options for a module. The result can be fed to compile:file/2 in order to compile the file again. The Beam argument, which can be a string or an atom, specifies either the module name or the path to the source code, with or with- out the ".erl" extension. In either case, the module must be known by the code server, i.e. code:which(Module) must succeed. Rules describes how the source directory can be found, when the object code directory is known. It is a list of tuples {BinSuffix, SourceSuffix} and is interpreted as follows: If the end of the directory name where the object is located matches BinSuffix , then the source code directory has the same name, but with BinSuffix replaced by SourceSuffix . Rules defaults to: [{"", ""}, {"ebin", "src"}, {"ebin", "esrc"}] If the source file is found in the resulting directory, then the function returns that location together with Options . Otherwise, the next rule is tried, and so on. The function returns {SourceFile, Options} if it succeeds. SourceFile is the absolute path to the source file without the ".erl" extension. Options include the options which are necessary to recompile the file with compile:file/2 , but excludes options such as report or verbose which do not change the way code is generated. The paths in the {outdir, Path} and {i, Path} options are guaran- teed to be absolute. Ericsson AB stdlib 1.17.3 filename(3erl)
All times are GMT -4. The time now is 02:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy