Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Adding an extension to a group of filenames Post 49767 by pepintheshort on Friday 9th of April 2004 05:24:21 PM
Old 04-09-2004
Optimus -
I expected more maturity than this from people who use this board. The name of the forum I'm posting in is "Unix Newbies". I am new to Unix, and I have figured out a fair amount on my own. I am not asking you to fix my problems or do my work for me - if I do not find the answer on this board, there are plenty of other sites on the net I can use, as well as - shock! - books I can read. The answer will appear eventually. I thought I was being very confident and trusting by posting the code I had already figured out without anyone else's help. Sort of a meet you halfway there proposition.

But let me just say that both your posts are relatively useless to me. You tell me something about Korn shell - I counter and tell you I'm using C Shell. Being new, I can't distinguish yet between those two shells and what differences there are. I tell you I don't want to use the mv command by itself, and you proceed to give me the definition of the mv command. Well, of course I know that it renames files as well as moves them - that's why I included a variation of it in my regex. The regex I've built is supposed to do the same thing your forloop does. (There's more than one way to do things - Larry Wall, right?) But neither of your posts point out where my error is - you just tell me I don't know how to think yet. I would have to counter and say you don't know the answer, don't care to answer and are in general a lazy poster who thinks he's too cool to forego his ego for a minute and genuinely help. Are you some kind of whiz kid who knew everything from the start and never had to rely on help from anyone else ever? Should I nominate you for sainthood, because that would be a miracle. I for one know I need help, and that is why I wanted to ask someone else. A little push in the right direction will do wonders.

Alright, enough of this ranting. I will try to explain this one more time, and see what happens.

I have one large text file with, say, 8000 lines. I have split this file into 8 new text files with 1000 lines in each. The text files, generated from this split command:

split -1000 thelist.txt project

result in files named "projectaa", "projectab", etc. I want their names to be "projectaa.txt", "projectab.txt", etc. Why I want to make this change is not important to you. Accept that this is what I want and move on. So, knowing that, I have decided that I could use filename expansion and try to add the extension on the name using sed and a substitute command "s/". I know that a simplified substitution looks like s/oldtext/newtext/. I also know that by adding the mv command here: s/oldtext/mv newtext/ almost works. It works better when I add the '&' to it, which automatically uses the pattern I've tried to match in the beginning. Hence: s/oldtext/mv '&' / Finally, I try adding my text to be changed, by escaping the period in the command, because it also has special metacharacter meanings. Now my sed command looks like s/oldtext/mv '&' \.txt/

So, in a nutshell, that's what I'm thinking. I added the ls -d* command first to list all files in the folder and pipe those to this sed command. I then piped that result to "sh" so that the shell would execute the command for every item in the folder. This is the equivalent of your forloop. The -v on the end just lets me see a verbose method so I can verify its working correctly.

Given all this information, I might not know if I placed a space incorrectly in the sed command, or misquoted or didn't escape something properly. That's what I wanted help with. Some way to make a regex that correctly identifies all files with the name "project" and two miscellaneous characters afterwards. I thought that /^project[a-z][a-z]$/ pretty well isolated it. But since its not working, I'm not sure what to try.

I'm not complaining that this isn't working. I wouldn't spend all day working out variations and doing research so I could complain here. I've got better things to do with my time and so do you.

So be the bigger man and post a relevant clue about my specific sed command and benefit all the other newbies who want an example of how to do the same thing. If you know the answer, put up or shut up.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading filenames with extension .xml

Hi, I want to write a script to read all the filenames with extension .xml in a directory and pass the name of the file, one by one, to another function. Please help me out. Regards. Saurabh (3 Replies)
Discussion started by: bhalotias
3 Replies

2. UNIX for Dummies Questions & Answers

removing the extension from all filenames in a folder

Hi there, I'm pretty new to UNIX and have tried trawling through this forum to find an answer to what I want to try to do, which I'm sure is very simple but I don't know how to do it. What I have a a folder that contains multiple files that I have copied from Windows and I want to remove the... (5 Replies)
Discussion started by: johnmcclintock
5 Replies

3. Shell Programming and Scripting

Help with adding to tar filenames

Hi there, i have been working on a backup script and have it just about working, the only problem im left with is that my filenames for my backups are all the same are replacing one another when backing up. currently i have BACKUP_FILE=backup_$(date +%d%m%y).tgz but would like something like... (2 Replies)
Discussion started by: Swinton
2 Replies

4. Shell Programming and Scripting

How to split a file with adding sequence number and extension.

I have a file name -HRCFTSIN05PLA1602100430444444 my requirement is to split the file in 10000 count each file and to add sequence number.rch at the end of each file. output should be in this format HRCFTSIN05PLA160210043044444401.rch HRCFTSIN05PLA160210043044444402.rch... (4 Replies)
Discussion started by: abhigrkist
4 Replies

5. Shell Programming and Scripting

Adding lines to files based on file extension

I have posted this before but did not get many replies, so here it goes again. I have several files name like this If the file extension is 1a, I woould like to add at the beggining of the file the following sequence If the file extension is 1b, thn the entry that should be added is the next... (2 Replies)
Discussion started by: Xterra
2 Replies

6. Shell Programming and Scripting

Adding the data before file extension

HI , I have a file with multiple lines like below, I need to check on column starting with #prototype if it has the .Number.txt extension do nothing else add 1.txt extension. Source data Jdbc_app_data :- sample data #prototype= sample data from test.1.txt application_id=122135... (4 Replies)
Discussion started by: gaur.deepti
4 Replies

7. Shell Programming and Scripting

Adding number before file extension

Hi , I have a file which has a line starts with $segment_name and has the below data source data $Segment_Name = 123.ABC.123.01.txt $Segment_Name = 123.ABC.ABC.txt $Segment_Name = 123.ABC.12A3.txtMy target data should be $Segment_Name = 123.ABC.123.01.txt $Segment_Name =... (2 Replies)
Discussion started by: shruthidwh
2 Replies

8. AIX

Adding a Volume Group to an HACMP Resource Group?

Hi, I have a 2 node Cluster. Which is working in active/passive mode (i.e Node#1 is running and when it goes down the Node#2 takes over) Now there's this requirement that we need a mount point say /test that should be available in active node #1 and when node #1 goes down and node#2 takes... (6 Replies)
Discussion started by: aixromeo
6 Replies

9. Shell Programming and Scripting

change filenames but not extension

I have a filename with a bunch of periods that I want to replace with underscores, but I don't want to change the extension. Ex: I want file.test1.f-1.fig.eps to be file_test1_f-1_fig.eps Using awk, the following line will replace ALL periods with underscores, but I want to leave the... (2 Replies)
Discussion started by: erinbot
2 Replies

10. Shell Programming and Scripting

How to remove filenames having the same extension.?

hi, i have a directory which contains some files and a subdirectory. i am writing only the files names to a file using the below code. ls -ltr | grep "^-" | awk '{print $NF}' > /home/file_list$$ cat /home/file_list$$ s1_abc.txt s2_def.xls s3_def.xls as you can see there is one .txt... (7 Replies)
Discussion started by: Little
7 Replies
putdgrp(1M)						  System Administration Commands					       putdgrp(1M)

NAME
putdgrp - edits device group table SYNOPSIS
putdgrp [-d] dgroup [device]... DESCRIPTION
putdgrp modifies the device group table. It performs two kinds of modification. It can modify the table by creating a new device group or removing a device group. It can also change group definitions by adding or removing a device from the group definition. When the command is invoked with only a dgroup specification, the command adds the specified group name to the device group table if it does not already exist. If the -d option is also used with only the dgroup specification, the command deletes the group from the table. When the command is invoked with both a dgroup and a device specification, it adds the given device name(s) to the group definition. When invoked with both arguments and the -d option, the command deletes the device name(s) from the group definition. When the command is invoked with both a dgroup and a device specification and the device group does not exist, it creates the group and adds the specified devices to that new group. OPTIONS
The following options are supported: -d Delete the group or, if used with device, delete the device from a group definition. OPERANDS
The following operands are supported: dgroup Specify a device group name. device Specify the pathname or alias of the device that is to be added to, or deleted from, the device group. EXIT STATUS
The following exit values are returned: 0 Successful completion. 1 Command syntax was incorrect, an invalid option was used, or an internal error occurred. 2 Device group table could not be opened for reading or a new device group table could not be created. 3 If executed with the -d option, indicates that an entry in the device group table for the device group dgroup does not exist and so cannot be deleted. Otherwise, indicates that the device group dgroup already exists and cannot be added. 4 If executed with the -d option, indicates that the device group dgroup does not have as members one or more of the specified devices. Otherwise, indicates that the device group dgroup already has one or more of the specified devices as members. EXAMPLES
Example 1 Adding a new device group. The following example adds a new device group: example# putdgrp floppies Example 2 Adding a device to a device group. The following example adds a device to a device group: example# putdgrp floppies diskette2 Example 3 Deleting a device group. The following example deletes a device group: example# putdgrp -d floppies Example 4 Deleting a device from a device group. The following example deletes a device from a device group: example# putdgrp -d floppies diskette2 FILES
/etc/dgroup.tab ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
listdgrp(1M), putdev(1M), attributes(5) SunOS 5.11 5 Jul 1990 putdgrp(1M)
All times are GMT -4. The time now is 11:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy