awk creating folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk creating folders
# 1  
Old 04-11-2014
awk creating folders

Hello, im trying to create folders from text file and i get errors Smilie

Code:
#!/bin/bash
awk 'BEGIN { RS = "/" } ; { mkdir $1, mkdir $2, mkdir $3, mkdir $4, mkdir $5}' zodziai.txt

im new in linux stuff just trying to learn. The idea is i want to create new folders from words in text file. I have 5 words in text file seperated by space. Can you help me? Thanks in advance
# 2  
Old 04-11-2014
Welcome to Forums..

You have to use system function, like this

Code:
awk '{command = "mkdir \"" $1 "\"" ; system(command)}' file

This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 04-11-2014
Thank you Smilie Can i use this for multiple files at once? Cause i added more variables after $1 and i get error :/
# 4  
Old 04-11-2014
You can do something like this

Creates 2 folders
Code:
$ awk 'function folder(arg){command = "mkdir \""arg"\"" ; system(command)}BEGIN{folder("First");folder("Second");}'


Code:
$ awk 'function folder(arg){command = "mkdir \""arg"\"" ; system(command)}{folder($1);folder($2);folder($3)}' zodziai.txt

This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 04-11-2014
Why do you want to use awk for this?
If you know that there are 5 names on one line in zodziai.txt, try:
Code:
read d1 d2 d3 d4 d5 < zodziai.txt
mkdir "$d1" "$d2" "$d3" "$d4 "$d5"

If you have one or more names on one or more lines in zodziai.txt, try something like:
Code:
while read -r line
do      set -- $line
        while [ $# -gt 0 ]
        do      mkdir "$1"
                shift
        done
done < zodziai.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Creating a sub-folder in multiple folders

Hi I've been trying to find an answer to this question and was hoping someone would be able to help me. I want to add a sub-folder to to an existing structure: for example /toys/toy_1/new /toys/toy_2/new /toys/toy_3/new There are humdreds of theses folders - what i want to do is add a... (2 Replies)
Discussion started by: LouSan
2 Replies

2. UNIX for Advanced & Expert Users

Help with creating script to delete log files/folders

Hi I am new to Linux / scripting language. I need to improve our Linux servers at work and looking to claim some space my deleting log files/ folders on a 5 day basis. Can someone help me with creating a script to do so. Any sample script will be helpful.:b: Regards (2 Replies)
Discussion started by: sachinksl
2 Replies

3. Shell Programming and Scripting

Creating matrix from folders and subfolders

Hello, Greetings! please help me produce the following solution. I need to produce one big matrix file from several files in different levels. If it helps, the index folder provides information on chromosome index and the data folder provides information on values for chromosomes. there... (8 Replies)
Discussion started by: newbie83
8 Replies

4. IP Networking

Accessingand creating folders in Machines using IP

Hi all, I am working on a project where I need to access four random machines from a given subnet mask and sending files across the machines similar to peer to peer file systems. Now my question is. Given a subnet mask or If I obtain a random IP address of a machine from Subnet mask, how can I... (4 Replies)
Discussion started by: Pavan Kumar
4 Replies

5. Shell Programming and Scripting

bash script for testing existence of files/folders and creating if neither exist

Hi, I am new to shell-scripting, and doing a lot of reading. I am having some trouble getting started with a simple testing of scripting. I have been experimenting with if, loops, for, test, etc., but still unsure. I seem to have the hang of it when it comes to creating a single file or... (6 Replies)
Discussion started by: me2
6 Replies

6. Shell Programming and Scripting

Creating folders based on number of files

I have hundreds of files numbered in consecutive number in one single folder What I would like to do is to make as many subfolders as needed (dependeing on the number of individual files) and name them Folder01, Folder02, etc. Then, move file01 to folder01, file02 to folder02 so on and so... (3 Replies)
Discussion started by: Xterra
3 Replies

7. Shell Programming and Scripting

Using cp: preserving file/folder attributes and auto creating folders

Hi, Is there a way to use cp in such a way that when a file is copied to a destination, the required destination folders are automatically created with the proper permissions, and the resulting copied file has the same attributes as the original. For example if I copied... (1 Reply)
Discussion started by: pcwiz
1 Replies

8. Shell Programming and Scripting

Creating links to multiple folders

Hi All, First of all, I'm a unix newbie so don't be to hard on me :) I'm not even sure if the thing that I want is even possible but here goes nothing: On my linux based NAS I have the following structure: videos |---movie 1 |---movie 2 |---movie 3 | USBDISK |---videos |--- movie... (8 Replies)
Discussion started by: kvb
8 Replies

9. Shell Programming and Scripting

Trouble with printing to other folders w/ awk

Again, I am in need of some advice. Earlier I was shown how to have awk create folders for me. That was so cool and helpful, but now I am exploring the posibilities of combining operations with bash scripts. Now, I am creating the directories with the bash script, and then I want awk to... (1 Reply)
Discussion started by: ccox85
1 Replies

10. Shell Programming and Scripting

SFTP:error while creating folders on remote server

Hi, I am trying to create some folders on remote server with SFTP connection. if the folder is exist then it is not executing the next commands. i.e. if temp/folder is exist then it it not executing mkdir $folder1 mkdir $folder2 commands. here is my code. sftp -b /dev/fd/0 ... (0 Replies)
Discussion started by: vgs
0 Replies
Login or Register to Ask a Question